jQuery.fn.valign = function() { $(this) .wrapInner('
') .css("position", "relative"); xH = $(this).children('.valign-box').height(); $(this).children('.valign-box') .css({ "position" : "absolute", "height" : xH, "top" : "50%", "margin-top" : 0-(xH/2) }); }; $(document).ready(function() { $("#viewer ul li").valign(); });