Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery parent().find() problem

HTML

<div class="comments">
    <a class="toggle" href="#">Toggle Comment 1</a><br />
    <div class="comment" style="display:none;">
        Comment1
    </div>
    <hr />
    <a class="toggle" href="#">Toggle Comment 2</a><br />
    <div class="comment" style="display:none;">
        Comment2
    </div>
</div>

JavaScript

$(function(){
    $('.toggle').click(function() {
        $(this).parent().find('.comment').slideToggle();
        return false;
    });
});

Can be viewed here: http://jsfiddle.net/saiprex/ESM4m/

How i can toggle comment that's been clicked and not all of them?

Cheers, Pav

like image 622
Pav Avatar asked May 12 '11 02:05

Pav


1 Answers

$(function(){
    $('.toggle').click(function() {
        $(this).nextAll('.comment:first').slideToggle();
        return false;
    });
});

jsFiddle.

like image 94
alex Avatar answered Nov 15 '22 22:11

alex