dgrafx
asked on
counting visible / hidden elements
for example when using the following code:
$("h3").click(function () {
$(this).next("p").slideTog gle("fast" );
hidden = $(this).parent().parent(". toggler"). find("div > p:hidden").length;
shown = $(this).parent().parent(". toggler"). find("div > p:visible").length;
console.log(hidden + ' : ' + shown);
});
<div class="toggler">
<a class="toggleall hand" onclick="return false;">Expand</a>
<div>
<h3 class="hand">Toggle 3</h3>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.
</p>
</div>
<div>
<h3 class="hand">Toggle 4</h3>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.
ut neque.
</p>
</div>
<div>
<h3 class="hand">Toggle 5</h3>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.
</p>
</div>
</div>
problem:
there are 3 toggle areas
i'm outputting the number of hidden p's & visible p's to the console
it starts off correctly but then gets behind by 1
see if you see what I mean.
Question:
What am i doing wrong and or is that a better way to do this?
$("h3").click(function () {
$(this).next("p").slideTog
hidden = $(this).parent().parent(".
shown = $(this).parent().parent(".
console.log(hidden + ' : ' + shown);
});
<div class="toggler">
<a class="toggleall hand" onclick="return false;">Expand</a>
<div>
<h3 class="hand">Toggle 3</h3>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.
</p>
</div>
<div>
<h3 class="hand">Toggle 4</h3>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.
ut neque.
</p>
</div>
<div>
<h3 class="hand">Toggle 5</h3>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.
</p>
</div>
</div>
problem:
there are 3 toggle areas
i'm outputting the number of hidden p's & visible p's to the console
it starts off correctly but then gets behind by 1
see if you see what I mean.
Question:
What am i doing wrong and or is that a better way to do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER