繁体   English   中英

jQuery-选择所有, <a>但有父母.x</a>

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

我想选择所有<a>但是那些有父母.x

我试过了

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

但意识到您需要一个选择器:not让它起作用。

您如何选择那些? 请帮忙!

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

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

我建议:

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

参考文献:

您可以执行以下操作:

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

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

    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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