0

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.

4 Answers 4

2

Using jQuery's :hidden should work in this case.

alert( $("#bob li:hidden").length );
Sign up to request clarification or add additional context in comments.

Comments

1
$('#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.

1 Comment

You're welcome. Study both jQuery selectors and (more generally) regular expressions. You will get an increase in productivity and faster code.
0

you can use jquery size

$("#bob li").is(':hidden').size()

1 Comment

"The .size() method is functionally equivalent to the .length property; however, the .length property is preferred because it does not have the overhead of a function call."
0

$('#bob > li:hidden').length should do.

Relevant links:

  • :hidden selector
  • .size():

    the .length property is preferred because it does not have the overhead of a function call

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.