<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery-3.2.1.min.js"></script>
<script>
$(function(){
$(".div1").next().css("background","pink");
$("span").prev().css("background","pink");
$("span").prev().css("background","pink");
$("#div2").find("h3").css("background","blue");
$("#div2").find("h2").css("background","orange");
alert($("#div2").index());
//index在所有兄弟节点中的位置:0,1,2……
})
</script>
</head>
<body>
<div class="div1">1</div>
<span>2</span>
<p id="p1">3</p>
<div id="div2">
<h3>h3</h3>
<h2>h2</h2>
<h3 id="sss">h3</h3>
<h3>h3</h3>
<h2>h2</h2>
<h3>h3</h3>
<h3>h3</h3>
<h2>h2</h2>
<h3>h3</h3>
<h2>h2</h2>
<h3>h3</h3>
</div>
</body>
</html>
07next
最新推荐文章于 2024-02-07 22:30:52 发布