元素子节点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>

猜你喜欢

转载自www.cnblogs.com/vinson-blog/p/12112723.html
今日推荐