Hanna
Hanna

Reputation: 10753

JQuery next class on click

Is there a way to grab the first class, after a given class?

The code below only selects the first class (I'm aware of what first does) but I want it to select each first .FAQAnswers after each FAQName is this possible?

 $(".FAQName").click(function () {
    $('.FAQAnswers').first().toggle(200);
 });


<div class="FAQName">Question</div>
...
<div class="FAQAnswers">Answer</div>

<div class="FAQName">Question</div>
...
<div class="FAQAnswers">Answer</div>

Upvotes: 0

Views: 40

Answers (1)

VisioN
VisioN

Reputation: 145398

You need to find the needed element with nextUntil:

$(".FAQName").click(function() {
    $(this).nextUntil(".FAQAnswers").next().toggle(200);
});

Upvotes: 3

Related Questions