I’m trying to get my head around jquery .has(). I tried to use it to find a li item that has a class=”a” and set its border.
<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>
$("li").has(".a")selects the same elements as$("li .a"), not$("li.a"). To select the same elements as$("li.a")with two different expressions, use$("li").filter(".a"). For your example it just makes sense to combine them, but if you wanted one of the two parts to be made a function argument, it may be useful to split them up.