jQueryfilter()方法
jQueryfilter()方法将返回与特定条件匹配的元素。
您可以尝试运行以下代码,以了解如何使用jQuery.filter()方法,
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").filter(".myclass").css("background-color", "gray");
});
</script>
</head>
<body>
<h1>Nhooo</h1>
<p class="myclass">Free Text Tutorials</p>
<p>Free Video Tutorials</p>
<p>Connecting Tutors</p>
</body>
</html>jQueryfind()方法
jQuery.find()方法将返回所选元素的后代元素。
您可以尝试运行以下代码,以了解如何使用jQuery.find()方法,
<!DOCTYPE html>
<html>
<head>
<style>
.myclass * {
display: block;
border: 2px solid red;
padding: 2px;
margin: 10px;
color: red;
}
</style>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("ol").find("span").css({"background-color": "blue", "border": "5px solid yellow"});
});
</script>
</head>
<body class="myclass">body
<div style="width:500px;">div
<ol>ol
<li>li
<span>The descendant element</span>
</li>
</ol>
</div>
</body>
</html>