jQuery content selector

:contains('john'): Indicates the tag containing the specified string, the string is case-sensitive
:empty: Indicates the element with an empty tag
:has('p'): Indicates the element with child elements
.addClass("style Name"): Add styles to all the tags
queried: parent: Indicates that the query is a non-empty tag

`
<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>

`

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325376859&siteId=291194637