I want to count the div that has a class name “items” and has an attribute “style=display:none”.
<div id="skills">
<div class="items" style="display:none">1</div>
<div class="items">2</div>
<div class="items">3</div>
<div class="items" style="display:none">4</div>
<div class="items" style="display:none">5</div></div>
the output should be ‘3’.
===========================================================
addition to the problem:
<div id="skills1">
<div class="items" style="display:none">1</div>
<div class="items">2</div>
<div class="items">3</div>
<div class="items" style="display:none">4</div>
<div class="items" style="display:none">5</div></div>
<div id="skills2">
<div class="items" style="display:none">1</div>
<div class="items" style="display:none">2</div>
<div class="items" style="display:none">3</div>
<div class="items" style="display:none">4</div>
<div class="items" style="display:none">5</div></div>
the output should be ‘3’ & ‘5’.
Original:
New:
The
countsobject will be:Last(?)
It would be even easier if you gave the “containers” a class to use as a selector. Then you could simply replace
#skills1,#skills2with the class selector and not have the function be dependent on the names of the DIVs, meaning that it wouldn’t have to change if you add another container, sayskills3. You’d just have to make sure to give that container the correct class.