Reputation: 260
If i have an html snippet
<div>
<ul style="display:block">
<li>A</li>
<li>B</li>
</ul>
<ul style="display:none">
<li></li>
<li></li>
</ul>
</div>
How to use jQuery to find the no. of ul elements in div with a css property of display: none
?
I know I can use $('div').children('ul').length
but this returns all ul elements
Upvotes: 2
Views: 3346
Reputation: 318182
You can filter for specific CSS values with a simple filter :
$('div ul').filter(function() {
return this.style.display === 'none';
}).length
Upvotes: 3
Reputation: 292
You should be able to use the :visible tag to find all the visible lists and then do $('ul:visible').length
or :hidden for the opposite to find the length.
Upvotes: 1
Reputation: 123739
You can use :hidden selector, if you want to get the length of hidden ul
s. It will take care of the ones with display:none
set. And similarly you have the :visible
selector as well.
$('div').children('ul:hidden').length
Elements can be considered hidden for several reasons:
Upvotes: 5