<div class="parent">
<div class="a"></div>
<div class="b"></div>
<div class="c"></div>
</div>
let children = document.querySelector('.parent').childNodes
console.log(children)
let array = []
for(let i=0;i<children.length;i++){
if(children[i].nodeType === 1 && children[i].className !== "a"){
array.push(children[i])
}
}
//找到了a的兄弟节点
思路:找出父节点,再找出所有子节点,for循环除去自己和多余的空格节点
网友评论