728x90
SMALL
#jquery
#:has()
:has()
:has() is a selector to use when selecting elements that contain a particular element.
grammar
$( ':has(selector)' )
for example
$( 'p:has(span)' )
Select the p element that has a span element.
example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery</title>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$( document ).ready( function() {
$( 'li:has( a )' ).css( 'border', '1px solid red' );
} );
</script>
</head>
<body>
<h1>jQuery Selector - :has()</h1>
<ul>
<li>Lorem</li>
<li><a href="#">Ipsum</a></li>
<li>Dolor</li>
<li>Sit</li>
<li><a href="#">Amet</a></li>
</ul>
</body>
</html>
Select the li element that has the a element as a child element to create a red border.
728x90
LIST