-
Notifications
You must be signed in to change notification settings - Fork 0
/
6_traverse.html
46 lines (44 loc) · 1.13 KB
/
6_traverse.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>...</title>
<script>
</script>
</head>
<body>
<!-- ul.top>(li.parent>ul>li.child*3)*2 -->
<ul class="top">
<li class="parent1">parent1
<ul>
<li class="child">child1</li>
<li class="child">child2</li>
<li class="child">child3</li>
</ul>
</li>
<li class="parent2">parent2
<ul>
<li class="child">child1</li>
<li class="child">child2</li>
<li class="child">child3</li>
</ul>
</li>
</ul>
<script src="js/jquery-1.11.3.js"></script>
<script>
//修改class为top的ul的所有直接子元素
$("ul.top").children()
.css("border","1px solid red")
//修改class为top的ul的所有后代li
$("ul.top").find("li")
.css("box-shadow","0 0 10px green")
//为class为child的li绑定单击事件
$("li.child").click(function(){
//选择当前元素的下一个元素/前一个元素/之前所有/之后所有/除自己之外所有
$(this).siblings()
//.nextAll()//.prevAll()//.prev()//.next()
.css("background","yellow")
})
</script>
</body>
</html>