Slidetoggle a div based on the link clicked
Trying to get the div with class sbox to slide up and down based on the stoggle that has been clicked. Can't figure this out. (I have hundreds of these so I'd like to set up something generic instead开发者_运维问答 of multiple different classes.)
$(".stoggle").click(function () {
$(this).slideToggle("fast");
});
<div class="wrapper">
<a class="stoggle" href="#">Read Bio</a>
<div class="sbox" style="display:none;">
Cras porta orci blandit at magna.
</div>
</div>
<div class="wrapper">
<a class="stoggle" href="#">Read Bio</a>
<div class="sbox" style="display:none;">
Lorem Ipsum
</div>
</div>
Give each a an id, like a-1
.
Give each .sbox an id, like a-1-div
.
In the click function:
$( '#' + $( this ).attr( 'id' ) + '-div' ).slideToggle("fast");
-- edit -- Try:
$( this ).next( '.sbox' ).slideToggle( 'fast' );
精彩评论