获取兄弟节点
<!DOCTYPE html>
<html>
<head>
<title>选取所有兄弟节点</title>
<meta charset="UTF-8">
<script src="/ajax/jquery/jquery-3.3.1.min.js"></script>
<style>
.box{
border: 1px solid black;
padding: 1px;
margin-bottom: 12px;
}
</style>
</head>
<body>
<div>
<ul id="ul">
<li id="a">油条</li>
<li id="b">包子</li>
<li id="c">米饺</li>
<li id="d"><a>鱼粉</a></li>
</ul>
</div>
<script>
$('#a').siblings().attr("class","box");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>获取下个兄弟节点</title>
<meta charset="UTF-8">
<script src="/ajax/jquery/jquery-3.3.1.min.js"></script>
<style>
.box{
border: 1px solid black;
padding: 1px;
margin-bottom: 12px;
}
</style>
</head>
<body>
<div>
<ul id="ul">
<li id="a">油条</li>
<li id="b">包子</li>
<li id="c">米饺</li>
<li id="d"><a>鱼粉</a></li>
</ul>
</div>
<script>
$('#c').next().attr("class","box");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>获取所有后面的兄弟节点</title>
<meta charset="UTF-8">
<script src="/ajax/jquery/jquery-3.3.1.min.js"></script>
<style>
.box{
border: 1px solid black;
padding: 1px;
margin-bottom: 12px;
}
</style>
</head>
<body>
<div>
<ul id="ul">
<li id="a">油条</li>
<li id="b">包子</li>
<li id="c">米饺</li>
<li id="d"><a>鱼粉</a></li>
</ul>
</div>
<script>
$('#a').naxtAll().attr("class","box");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>获取所有后面的节点,但不包含其中的一个</title>
<meta charset="UTF-8">
<script src="/ajax/jquery/jquery-3.3.1.min.js"></script>
<style>
.box{
border: 1px solid black;
padding: 1px;
margin-bottom: 12px;
}
</style>
</head>
<body>
<div>
<ul id="ul">
<li id="a">油条</li>
<li id="b">包子</li>
<li id="c">米饺</li>
<li id="d"><a>鱼粉</a></li>
</ul>
</div>
<script>
$('#a').nextUntil().attr("class", "box");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>获取所有前面的节点</title>
<meta charset="UTF-8">
<script src="/ajax/jquery/jquery-3.3.1.min.js"></script>
<style>
.box{
border: 1px solid black;
padding: 1px;
margin-bottom: 12px;
}
</style>
</head>
<body>
<div>
<ul id="ul">
<li id="a">油条</li>
<li id="b">包子</li>
<li id="c">米饺</li>
<li id="d"><a>鱼粉</a></li>
</ul>
</div>
<script>
$('#d').prevAll().attr("class", "box");
</script>
</body>
</html>