Home > Web Front-end > JS Tutorial > body text

jquery content filtering

无忌哥哥
Release: 2018-06-29 11:25:53
Original
1609 people have browsed it

<body>
<h2>春晓</h2><span></span>
<p>春眠不觉晓,处处闻啼鸟。</p>
<p>夜来风雨声,花落知多少</p>
<p>我的女神:<img src="../images/gyy.jpg" width="150"></p>
<p>我想对圆圆:<input type="" name=""><button>提交</button></p>
</body>
Copy after login
<script type="text/javascript" src="../js/jquery-3.3.1.js"></script>
<script type="text/javascript">
Copy after login

//1. Select elements containing specified text content

$(&#39;p:contains(\&#39;春\&#39;)&#39;).addClass(&#39;bg-wheat&#39;)
$(&#39;p:contains("春")&#39;).addClass(&#39;bg-wheat&#39;)
$(&#39;p:contains("风")&#39;).addClass(&#39;bg-green&#39;)
Copy after login

//2. Select tags with empty content. Empty means that there are no sub-tags, not even text content.

$(&#39;:empty&#39;).text(&#39;作者:孟浩然&#39;)
Copy after login

//3. Select the p element with the img tag (picture) and add a background to it

$(&#39;p:has("img")&#39;).addClass(&#39;bg-pink&#39;)
Copy after login

//4. Select all nodes with p as the parent element and add a green background

$(&#39;p:parent&#39;).addClass(&#39;bg-green&#39;)
Copy after login

//5. Invert the filter not, select all elements on the page that are not empty, and change the foreground color to red

$(&#39;:not(:empty)&#39;).css(&#39;color&#39;,&#39;red&#39;)
Copy after login
</script>
Copy after login

The above is the detailed content of jquery content filtering. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!