标签:jQuery内容选择器
:contains(‘john‘):表示包含指定字符串的标签,字符串大小写敏感`
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="../js/jquery-1.6.js"></script>
<style type="text/css">
.myClass{
font-size:44px;
color:blue
}
</style>
</head>
<body>
<div><p>John Resig</p></div>
<div><p>George Martin</p></div>
<div>Malcom John Sinclair</div>
<div>J. Ohn</div>
<p></p>
<p></p>
<div></div>
<script type="text/javascript">
//1)查找所有包含文本"John"的div元素的个数
//alert($("div:contains(‘john‘)").size());
//2)查找所有p元素为空的元素个数
//alert($("p:empty").size());
//3)给所有包含p元素的div元素添加一个myClass样式
//$("div:has(‘p‘)").addClass("myClass");
//4)查找所有含有子元素或者文本的p元素个数,即p为父元素
alert($("p:parent").size());
</script>
</body>
</html>
`
标签:jQuery内容选择器
原文地址:http://blog.51cto.com/357712148/2113188