From jQuery JavaScript Library
« Back to Selectors
:has(selector)
Matches elements which contain at least one element that matches the specified selector.
Arguments:| selector | Selector | |
|---|
| A selector with which to filter by. |
Examples:| Name | Type |
Adds the class "test" to all divs that have a paragraph inside of them.
$("div:has(p)").addClass("test");
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="../jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("div:has(p)").addClass("test");
});
</script>
<style>
.test{ border: 3px inset red; }
</style>
</head>
<body>
<div><p>Hello in a paragraph</p></div>
<div>Hello again! (with no paragraph)</div>
</body>
</html>