简体   繁体   中英

$(this) selector and his descendant

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?

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();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM