0

I am dynamically displaying multiple rows of div's.

Div sets look like this:

<div class="triggerbutton">
    <img src="/images/clickme.png" alt="" />
</div>

<div class="hiddendivs" style="display:none;">
    some stuff here 
</div>

I am using this JQuery:

$('.triggerbutton').click(function() {

    $('.hiddendivs').show('slow');

});

But I only want the hiddendivs after the triggerbutton to be showed and not all the hiddendivs available.

How can I do this?

4

5 回答 5

7

Assuming hiddendivs is the next sibling you could use

$('.triggerbutton').click(function() {
    $(this).next().show('slow');
});
于 2013-07-17T12:52:29.347 回答
2
$('.triggerbutton').click(function() {
   $(this).closest('.hiddendivs').show('slow');
});
于 2013-07-17T12:52:11.797 回答
2

you can use .next() in jQuery

$('.triggerbutton').click(function() {

    $(this).next().show('slow');

});
于 2013-07-17T12:53:01.407 回答
1

Try with code. It works like this, find next immediate div with class hiddendivs and shows it.

$('.triggerbutton').click(function() {

    $(this).next('div.hiddendivs').show('slow');

});
于 2013-07-17T12:55:06.060 回答
1

Using next you will only refer to the next element following the selector. You can also use nextAll for all following divs:

$('.triggerbutton').click(function() {
    $(this).nextAll('.hiddendivs').show('slow');
});

Fiddle here

于 2013-07-17T12:59:09.280 回答