码迷,mamicode.com
首页 > Web开发 > 详细

jQuery内容选择器

时间:2018-05-06 11:09:03      阅读:321      评论:0      收藏:0      [点我收藏+]

标签:jQuery内容选择器

:contains(‘john‘):表示包含指定字符串的标签,字符串大小写敏感
:empty:表示查询空标签的元素
:has(‘p‘):表示查询有子元素的元素
.addClass("样式名"):为查询到的所有标签添加样式
:parent:表示查询非空标签

`
<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内容选择器

标签:jQuery内容选择器

原文地址:http://blog.51cto.com/357712148/2113188

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!