国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

jQuery traversal - descendants

Traverse down the DOM

children()

find()


children() method

The children() method returns all direct children of the selected element (only children).

The parameters are optional. Adding parameters means filtering through the selector and filtering the elements.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.descendants *
{ 
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("div").children("p.1").css({"color":"blue","border":"5px solid green"});
});
</script>
</head>
<body>
<div class="descendants" style="width:300px;">
  <p class="1">p (兒子元素)
    <span>span (孫子元素)</span>     
  </p>
  <p class="2">p (兒子元素)
    <span>span (孫子元素)</span>
  </p> 
</div>
</body>
</html>

Returns all <p> elements with class name "1" that are direct children of <div>


find( ) Method

find() method returns the descendant elements of the selected element, all the way down to the last descendant.

The parameter is required and can be a selector, jQuery object or element to filter elements.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.descendants *
{ 
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("div").find("span").css({"color":"red","border":"3px solid blue"});
});
</script>
</head>
<body>
<div class="descendants" style="width:300px;"> 
  <p>p (兒子元素)
    <span>span (孫子元素)</span>     
  </p>
  <p>p (兒子元素)
    <span>span (孫子元素)</span>
  </p> 
</div>
</body>
</html>

Returns all <span> elements that are descendants of <div>.

Continuing Learning
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("ul.level-2").children().css({"background-color":"gray","width":"200px"}); }); </script> </head> <body> <ul class="level-1"> <li class="item-i">I</li> <li class="item-ii">II <ul class="level-2">不包括自己 <li class="item-a">A</li> <li class="item-b">B <ul class="level-3"> <li class="item-1">1</li> <li class="item-2">2</li> <li class="item-3">3</li> </ul> </li> <li class="item-c">C</li> </ul> </li> <li class="item-iii">III</li> </ul> </body> </html>
submitReset Code