我正在尝试了解 jquery .has()。我尝试使用它来查找具有 class="a"的 li 项目并设置其边框。
<script type=text/javascript>
$("document").ready( function(){
$("li").has(".a").css("border", "3px solid red");
});
<ul id="list1">
<li class="a">item 1</li>
<li class="a">item 2</li>
<li class="b">item 3</li>
<li class="b">item 4</li>
</ul>
最佳答案
.has()
查找与提供的选择器匹配的后代元素。来自 the API docs :
.has( selector )
Description: Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.
你想做的事情要简单得多!
$("li.a").css("border", "3px solid red");
关于jquery - jquery 中的 .has(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6021751/