I can not directly user $(‘commentbody’) because there are many comments and selection needs to be done withing this specific area.
Html:
<div class="commentline">
<div class="carrowholder">
<div class="ctoggle"></div>
<div class="arrowwrap">
</div>
</div>
<div class="commentholder">
<div class="commenttitle">
Title
</div>
<div class="commentbody">
Body
</div>
</div>
</div>
jQuery:
$('.ctoggle').click(function(e) {
$(this).parent().next('.commentholder > .commentbody').hide();
})
Your attempt fails because you are looking for a sibling of the parent element that matches the selector:
No sibling is ever going to match that (
.commentholderis a sibling, but you’re looking for a child of that), so you need to move the child selector out. You can usechildren(orfind):