元素子节点children

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>元素子节点children</title>
    <!-- 
        node.children;获取node节点下的所有 元素 子节点
        node.childElementCount;获取node节点下所有元素子节点的数量
     -->
</head>
<body>
    <p></p>
    <script>
        var a=document.body.childNodes;//获取所有子节点
        var b=document.body.children;//获取元素子节点
        console.log(a);//[text,p,script,text]
        console.log(NodeList.length)
        console.log(b);//[p,script]
        console.log(document.body.childElementCount);//2
    </script>
</body>
</html>

posted on 2019-12-28 19:03  loongw  阅读(311)  评论(0编辑  收藏  举报

导航