Reputation: 25
Im trying to select a descendant class of $(this)
.
Here an example :
<div class="family">
<div class="brother">CLICK HIM</div>
<div class="cousin"></div>
<div class="sister">TO SELECT HER</div>
</div>
<div class="family">
<div class="brother"></div>
<div class="cousin"></div>
<div class="sister">AND NOT HER</div>
</div>
I want to click on .brother and want to select his .sister
!
with the following code I would select the child of .sister
, but thats not what I want to do.
$('.brother').click(function() {
$('.sister', this).hide();
});
could anybody help me?
Upvotes: 2
Views: 65
Reputation: 68393
You could use jQuery function nextAll() with a selector :
$('.brother').click(function() {
$(this).nextAll( ".sister" ).hide();
});
Or jQuery function siblings() with a selector :
$('.brother').click(function() {
$(this).siblings( ".sister" ).hide();
});
Upvotes: 6