Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how I can find with jQuery the next element?

Tags:

html

jquery

css

how I can find the next class "comment" and shows it after I click "read" ?

<div class="preview">
<div class="messages">
    <div class="msg">
        <div class="circle left"><img src=""></div>
        <div class="name">Lars Mehrhoff</div>
        <div class="sep_20"></div>
        <a href="#" class="read"><i class="icon-comment"></i></a>
        <a href="#" class="reply"><i class="icon-reply"></i></a>
        <a href="#" class="read"><i class="icon-ok"></i></a>
        <a href="#" class="trash"><i class="icon-trash"></i></a>
        <div class="comment">ASD</div>
    </div>

    <div class="clearfix"></div>

    <div class="msg">
        <div class="circle left"><img src=""></div>
        <div class="name">Lars Mehrhoff</div>
        <div class="sep_20"></div>
        <a href="#" class="read"><i class="icon-comment"></i></a>
        <a href="#" class="reply"><i class="icon-reply"></i></a>
        <a href="#" class="read"><i class="icon-ok"></i></a>
        <a href="#" class="trash"><i class="icon-trash"></i></a>
        <div class="comment">ASD</div>
    </div>
</div>

And my jQuery Code is this:

    $('.read').click(function(e) {
    $(this).find('.comment').show();
});

$('.comment').hide();

I would display only the comment that is next to the "read"

like image 726
Evolutio Avatar asked Jan 17 '26 05:01

Evolutio


1 Answers

You can use the .siblings() method:

$(this).siblings(".comment").show();
like image 64
97ldave Avatar answered Jan 19 '26 18:01

97ldave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!