1

How can I find number of none hidden rows, Here is the html

<div style="display:none;">
  <ul id="abc">
    <li>List Item</li>
    <li>List Item</li>
    <li style="display:none;">List Item</li>
    <li class="hidden">List Item Hidden</li>
  </ul>
</div>

CSS

ul { border: 1px solid blue; padding: 2px; margin: 2px;}
li { width: 100px; height:100px; background-color:blue;}
.hidden { display: none; }

jQuery

$(function () {
    alert($("#abc li:not(:hidden)").length);
});

http://jsfiddle.net/76NNp/27/

EDIT

The Code works as expected but what I want is

Finding Number of hidden List Items within a hidden Div...

Note: it's a pop-up list, I am using some code to .hide() and .show() li but while list has display:none; I still want to find out how many items are visible, as if it's zero, i would hide the button that opens this pop-up list

EDIT------------------------------------------2

FORGET EVERYTHING...

I want to find out number of not hidden list items that will become visible if Div they are in becomes visible.

Simple as milk now :-)

Mathematics
  • 7,314
  • 25
  • 77
  • 152

2 Answers2

2

You can filter the elements and check if their display style is set to none. Something like this:

$(function () {
    var items = $("li").filter(function(){
        return $(this).css("display") != "none";
    });
    alert(items.length);
});

Here is a working example

NOTE: This heavily depends on display:none; being the only factor that determines if an element is visible or not. If you use other methods such as visibility:hidden; then you will need to modify your filter to account for that.

musefan
  • 47,875
  • 21
  • 135
  • 185
1

Try this my friend:

    $(function () {
    $i = 0;
    $("ul > li").each(function(){
        if(!$(this).hasClass('hidden') || $(this).css('display') != 'none')
            $i++;
    });
    alert($i);
});
Jain
  • 1,209
  • 10
  • 16