I’m trying to add a <li> inside an <ul> if the <li> count is less or equal to 20, but the code doesn’t seem to be working…
I’m using the following jQuery:
while ($(".mosaico > li").length() <= 20) {
$('.mosaico').append('<li>test</li>');
};
And nothing seems to happen… The HTML is:
<ul class="mosaico">
<li>
</li>
<li>
</li>
<li>
</li>
</ul>
.lengthis a property, not a function.But you shouldn’t run the selector in a loop like that. Just calculate how many you need, and add them all at once.
http://jsfiddle.net/pQXNT/2