如何获得包含每个匹配元素集的所有唯一直接子元素的元素集?
children([selector])方法获取一组元素,其中包含每个匹配元素集的所有唯一直接子代。
示例
您可以尝试运行以下代码,以了解如何获取包含每个匹配元素集的所有唯一立即子元素的元素集:
<html><head>
<title> jQuery Example</title>
<script src = "https://cdn.staticfile.org/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("div").children(".selected").addClass("blue");
});
</script>
<style>
.blue {
color:blue;
}
</style>
</head>
<body>
<div>
<span>Hello</span>
<p class = "selected">Hello Again</p>
<div class = "selected">And Again</div>
<p class = "biggest">And One Last Time</p>
</div>
</body>
</html>
<style>
.selected {
color:blue;
}
</style>
</head>
<body>
<p>This is first paragraph and <span>THIS IS BLUE</span></p>
<p>This is second paragraph and <span>THIS IS ALSO BLUE</span></p>
</body>
</html>
以上是 如何获得包含每个匹配元素集的所有唯一直接子元素的元素集? 的全部内容, 来源链接: utcz.com/z/322133.html