Use the scrollHeight DOM property supported by all modern browsers (even IE):
var wholeHeight = $("ul")[0].scrollHeight;
Alternatively, you can select the first and last item in the list, get the top offset and align them from each other. Add the height of the final list item and the result will be equivalent to scrollHeight (after adding the upper and lower paddings of UL).
var ul = $("ul"), last = ul.children().last(); var wholeHeight = last.offset().top - ul.children().first().offset().top + last.outerHeight() + parseFloat(ul.css("padding-top")) + parseFloat(ul.css("padding-bottom"));
Note. The first method is much more efficient. The second method may not give the correct result when the last element is absolutely positioned or floating.
Rob w source share