Reputation: 1570
I need to find the QUANTITY of all of the instances of ONLY the <li style="display:none;">
UNDER ONLY the <ul id="bob">
, as I will have other <li>
pieces throughout document:
e.g.:
<ul>
<li> a </li>
<li> b </li>
<li> c </li>
</ul>
<ul id="bob">
<li style="display:none;"> 1 </li>
<li style="display:none;"> 2 </li>
<li style="display:none;"> 3 </li>
<li style="display:inline-block;"> 4 </li>
<li style="display:inline-block;"> 5 </li>
<li style="display:inline-block;"> 6 </li>
</ul>
The amount of <li>
are dynamically generated in my script, so it's not an obvious, visible number like '3' in this case.
Upvotes: 0
Views: 193
Reputation: 12302
$('#bob li[style*="display:none"]')
This will find all your li elements inside #bob, with a style attribute containing the word "display:none".
var elements = $('#bob li[style*="display:none"]');
elements.length;
This will give you the number of elements found.
You can see this fiddle here.
Upvotes: 1
Reputation: 24254
Using jQuery's :hidden
should work in this case.
alert( $("#bob li:hidden").length );
Upvotes: 2
Reputation: 15853
$('#bob > li:hidden').length
should do.
Relevant links:
the .length property is preferred because it does not have the overhead of a function call
Upvotes: 0