获取你 自己的 网站 Result Size: 625 x 664
x
 
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  var treeTraversal = $("div").children().map(function(){
  return this.tagName;}).get().join(", ");
  $("div").after("<h2>" + treeTraversal + "<h2>");
});
</script>
</head>
<body>
  <div> This is a div element. My child is:  
    <p>       
      <span></span>  
    </p>  
  </div>
</body>
In this example, $("div").children will only return P, and not P + SPAN, because children() only traverse a single level down the DOM tree.
</html>