Last Updated: February 25, 2016
·
1.214K
· pascalgerritsen

Vertical align any element using jQuery

 $(function() {
    $('element').each( function( index, item) {
        var parent = $(item).parent();
        var $this = $(item);
        parent.css('position', 'relative');
        $this.css('position', 'absolute').css('top', Math.round((parent.height() - $this.outerHeight()) / 2) + 'px');
    }); 
});