如何在jQuery中找到特定类型元素的后代元素?

使用jQueryfind()方法在jQuery中查找特定类型的元素的后代元素。jQuery.find()方法将返回所选元素的后代元素。

示例

您可以尝试运行以下代码,以了解如何使用jQuery.find()方法,

<!DOCTYPE html>
<html>
<head>
<style>
 .myclass * {
    display: block;
    border: 2px solid red;
    padding: 2px;
    margin: 10px;
    color: red;
 }
</style>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
  $(document).ready(function(){
    $("ol").find("span").css({"background-color": "blue", "border": "5px solid gray"});
  });
</script>
</head>

<body class="myclass">body
  <div style="width:500px;">div
    <ol>ol  
      <li>li
        <span>The descendant element</span>
      </li>
    </ol>  
  </div>
</body>

</html>