实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<style>
5
.descendants *
6
{ 
7
display: block;
8
border: 2px solid lightgrey;
9
color: lightgrey;
10
padding: 5px;
11
margin: 15px;
12
}
13
</style>
14
<script src="https://libs.baidu.com/jquery/1.10.2/jquery.min.js">
15
</script>
16
<script>
17
$(document).ready(function(){
18
  $("ul").children().css({"color":"red","border":"2px solid red"});
19
});
20
</script>
21
</head>
22
23
<body class="descendants">body (great-grandparent)
24
  <div style="width:500px;">div (grandparent)
25
    <ul>ul (direct parent)  
26
      <li>li (child)
27
        <span>span (grandchild)</span>
28
      </li>
29
      <li>li (child)
30
        <span>span (grandchild)</span>
31
      </li>
32
    </ul>   
33
  </div>
34
</body>
35
36
</html>