<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>
<script type="text/javascript" src="../js/jquery-3.3.1.js"></script> <script type="text/javascript">
//1. Select elements containing specified text content
$('p:contains(\'春\')').addClass('bg-wheat') $('p:contains("春")').addClass('bg-wheat') $('p:contains("风")').addClass('bg-green')
//2. Select tags with empty content. Empty means that there are no sub-tags, not even text content.
$(':empty').text('作者:孟浩然')
//3. Select the p element with the img tag (picture) and add a background to it
$('p:has("img")').addClass('bg-pink')
//4. Select all nodes with p as the parent element and add a green background
$('p:parent').addClass('bg-green')
//5. Invert the filter not, select all elements on the page that are not empty, and change the foreground color to red
$(':not(:empty)').css('color','red')
</script>
The above is the detailed content of jquery content filtering. For more information, please follow other related articles on the PHP Chinese website!