简体   繁体   中英

Jquery - select all <a>s but those have parents .x

I want to select all <a> s but those have parents .x

I've tried

$(":not(.x)").find("a")

but realized you need a selector before :not for it to work.

How can you select those? Please help!

您可以选择所有元素,然后排除.xa元素,例如

$("a").not(".x a")

I'd suggest:

$('a').filter(function(){
    return $(this).closest('.x').length === 0;
});

References:

You do something like this:

$('a').each(function(){

    if ($(this).parent().hasClass('x')){
        // Do Something

    }
});

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