How to implement a browser-compatible version of element.children?
PHP中文网
PHP中文网 2017-05-19 10:22:40
0
1
437
<body>
<p id="ap">
<h1>name</h1><p>contentcontentcontent<span>content</span></p></p>
<script>
var someElement={
    children:function(element){
        if(element.children){
            console.log(element.children);
        } else {
            var i,
                len=element.childNodes.length;
            for(i=0;i<len;i++){
                if(element.childNodes[i].nodeTypoe == 1){
                    element.childNodes[i];//怎样把得到的元素节点放在一起,之前搜过,说是放在数组里,可那个不是HTMLCollection啊。
                }
            }
        }
    }
};
var p = document.getElementById("ap");
someElement.children(p);
</script>
</body>
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
仅有的幸福

To shield the compatibility issues of browser DOM operations, jquery is still the first choice

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!