jQuery content filter selector
Content filter selector
:contains(content)
Contains content selector, the inside of the obtained node must contain the specified content through the tag
$("div:contains(beijing)")
<div>linken love beijing</div>
<div>jack love shanghai</div>
:empty
Get the empty element (no element/text (empty) inside) node object
$("div:empty")
<div>linken love beijing</div>
<div>jack love shanghai</div>
<div></div>
< ;div><img /></div>
<div>
:has(selector)
The selector that contains the specified element inside $(“div:has(#apple)”)<div>hello</div>
<div><p></p></div>
<div> ;<span id=”apple”></span></div>
:parent
looking for The node must exist as a parent element node$("div:parent")##<div>linken love beijing</div>
<div>jack love shanghai</div>
<div></div>
<div><img /> ;</div>##<div> </div>
<!DOCTYPE html> <html> <head> <title>php.cn</title> <meta charset="utf-8" /> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> function f1(){ //① $(":contains(text)") $("div:contains(beijing)").css('background-color','red'); //② $(":empty") $("div:empty").css('width','200px'); $("div:empty").css('height','100px'); $("div:empty").css('background-color','pink'); //③ $(":has(selector)") console.log($("div:has(.orange)")); //④ $(":parent") console.log($("div:parent")); } </script> </head> <body> <h1>内容过滤选择器</h1> <div>i love beijing</div> <div>jack love shanghai</div> <div></div> <div><img /></div> <div> </div> <div><p class="orange"></p></div> <div><span class="orange"></span></div> <input type="button" value="触发" onclick="f1()" /> </body> </html>