现在的结果有3个ul,第三个ul有一个叫做tree的类
我希望在$(node.target).parents("ul[class!='.tree']")这条语句中,不会选择中第三个有tree类的ul。
但这条选择器不能,选择出来的还是有第三个ul,我应该怎么写一条,选择出不包括某个类的选择器语句呢?
if($(node.target).parent().hasClass("tree")){
return;
}else{
console.log($(this).parent())
}
加个if的判断如何?
.not(selected)
$("#btn").parents().find("ul[class!='tree']")
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
console.log($("#btn").parents().find("ul[class!='tree']"))
});
</script>
</head>
<body>
<div>
<ul><li></li></ul>
<ul><li></li></ul>
<ul class="tree"><li></li></ul>
<button type="button" id="btn">Click me</button>
</div>
</body>
</html>
$(node.target).closest("包含所有ul的父元素").find("ul[class!='tree']")
$(node.target).parents("ul[class='.tree']:not(eq(2))")
$("#id").find("img").length == 0 不包含img标记的标签
高级点的
1
1
$("div:not(:has(span))") ;//选中div 节点下不包含span标记的div元素