Home >>jQuery Tutorial >jQuery :has() Selector
jQuery :has() selector in jQuery is used to selects all elements that have one or multiple elements inside of them, that matches the specified selector.
Syntax:$(":has(selector)")
Parameter | Description |
---|---|
selector | It is a Required parameter and used to specifies the element to select. |
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p:has(span)").css("border", "solid #97d7fc");
});
</script>
</head>
<body>
<p><span>span element inside a p element.</span></p>
<p>p element with no span element.</p>
</body>
</html>
span element inside a p element.
p element with no span element.