E:has(F)
匹配所有的E元素,满足E元素中至少有一个F元素。返回匹配结果集
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/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>
$("div:has(p)").addClass("test");
匹配所有div中包含P元素的div集合,以下为匹配的元素
<div><p>Hello in a paragraph</p></div>