Reputation: 77
have a code structure like this :
<ul class="ulNotif">
<span id="notiftype1"></span>
<span id="notiftype2"></span>
<span id="notiftype3"></span>
</ul>
I sent li with jquery to each span. Every span will have li if the data match with the condition.
I tried to count with $(".ulNotif span li").length
but still 0 value.
How to count span which have li inside it with javascript? Thanks
Upvotes: 0
Views: 300
Reputation: 1403
@junkfoodjunkie is correct. You should use <li>
tags as direct descendants of <ul>
. Nonetheless, your code should look like this:
$(".ulNotif span li").length
Your <ul>
has a .class, not an #ID
EDIT: This works totally find for me: returns 3
$('.ulNotif span').each((index, child) => {
$(child).append('<li>')
})
console.log($('.ulNotif span li').length)
Upvotes: 2