What’s wrong with this?
I’m trying to hide all empty li.
$(document).ready(function() {
$("#details li").each(function() {
if ($(this).length == 0) {
$(this).css({ display: "none" }); ;
}
});
});
Markup:
<ul id="details">
<li>Lorem Ipsum</li>
<li>Lorem Ipsum</li>
<li>Lorem Ipsum</li>
<li>Lorem Ipsum</li>
<li></li>
<li></li>
<li>Lorem Ipsum</li>
<li>Lorem Ipsum</li>
<li>Lorem Ipsum</li>
</ul>
Thank you in advance
I think what you want is the
.text()length, like this:Or a bit shorter:
Or a slightly different check that works for your purposes, courtesy of @Rafael: