因为三种方法之间存在着相似之处,因此将它们放在一起去比较
1、children获得匹配元素的所有子元素组成的集合
2、next方法,取得一个紧邻后面元素集合
3、nextAll方法,取得当前元素之后所有的同辈元素
请看以下实例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="../js/jquery-3.3.1.js"></script>
</head>
<body>
<table>
<th>
<td>序号</td>
<td>姓名</td>
</th>
<tr>
<td>1</td>
<td>小明</td>
</tr>
<tr>
<td>2</td>
<td>李华</td>
</tr>
</table>
<script>
$("body").children().each(function(){
console.log(this);
});
$("th").next().each(function(){
console.log(this);
});
$("th").nextAll().each(function(){
console.log(this);
})
</script>
</body>
</html>
它运行后的效果为:
解析该程序:
children方法会得到< table>< /table> < script>< /script>
next方法会得到< th>后的第一个< td>< /td>
而nextAll会得到< th>后所有的< td>< /td>