How to count list items that are not hidden?
Starting with a simple list:
<ul> <li>Item 1</li> <li style="display: none;">Item 2</li> <li>Item 3</li> </ul> I know that I can subtract hidden elements from the general list
$('ul li').size() - $('ul li:hidden').size() But I thought there might be a more elegant way to achieve this with jquery:
$('ul li:hidden:not').size() This does not work. Any ideas?
+6
Baloneysammitch
source share2 answers
The simplest form:
var hidden = $("ul > li:hidden").length; In a side note, to correctly use :not() :
var hidden = $("ul > li:not(:visible)").length; Finally, the jQuery object supports the size() method and the length property, which are interchangeable.
+2
cletus
source share