JS、JQ获取容器内标签的个数

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>获取容器内标签的个数</title>
</head>
<body>
<div class="content" id="content">
    <div class="item"><span></span><span></span></div>
    <div class="item"><span></span><span></span></div>
    <div class="item"><span></span><span></span></div>
    <div class="item"><span></span><span></span></div>
    <div class="item"><span></span><span></span></div>
</div>
    <script src="http://www.jq22.com/jquery/jquery-2.1.1.js"></script>
    <script type="text/javascript">
      window.onload = function(){
          var div_l = $(".content").children(".item").length;//JQ获取标签个数方法
        console.log("jq方法:",div_l);

        var div_m = document.getElementById("content");
        var div_n = div_m.getElementsByClassName("item").length;//js获取标签个数方法
        console.log("js方法:",div_n);
      }
    </script>
</body>
</html>
原文地址:https://www.cnblogs.com/liangdecha/p/9675202.html