I have many lists with different items:
<div id="listsContainer">
<ul>
<li>lorem lipsum</li>
<li>lorem lipsum</li>
</ul>
<ul>
<li>lorem lipsum</li>
<li>lorem lipsum</li>
<li>lorem lipsum</li>
</ul>
<ul>
<li>lorem lipsum</li>
<li>lorem lipsum</li>
<li>lorem lipsum</li>
<li>lorem lipsum</li>
</ul>
</div>
There are lists with 2 elements and others lists with 3 elements etc.
I would like to add empty elements to the lists that contains fewer elements than that which contains many elements to have lists with the same number of elements.
I tried so and it works:
$("ul").each(function() {
$( this ).find("li").addClass("total-elements"+ $(this).children().length );
if($(this).children().length == 3) {
$(this).append( "<li></li>" );
}
if($(this).children().length == 2) {
$(this).append( "<li></li><li></li>" );
}
});
The problem is that I don't know how many items have the list with many items (is not always 4).
Is there a way to check which list contains many elements than the others dynamically and add elements to the other lists to achieve lists with equal number of elements?