Link to home
Start Free TrialLog in
Avatar of dgrafx
dgrafxFlag for United States of America

asked on

counting visible / hidden elements

for example when using the following code:

$("h3").click(function () {
        $(this).next("p").slideToggle("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?
ASKER CERTIFIED SOLUTION
Avatar of Ahmed Hussein
Ahmed Hussein
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dgrafx

ASKER

thanks ...