I am trying to loop through multiple lists on a page and depending on the number of items per list, I want to get the height of the each li and set the max height (for 5 items) and set a scrollbar.
I have the following script that goes through each list found and returns the length correctly but I cannot get the height of each li. Thanks for any help.
JQUERY::
$(".list-item").each(function () {
var sum = 0;
var getLength = $(this).children().children().children('ol li').length;
console.log(getLength);
//Get length of list items and add scroll bar if more than 5
if (getLength > 5) {
$(this).addClass('maxLength');
$('.maxLength ol li:lt(5)').each(function () {
sum += $(this).height();
console.log(sum);
});
$('.maxLength ol').css({ maxHeight: sum + 'px', overflow: 'auto' });
}
});