childNodes
gets all existing childNodes, including text nodes! In your example markup, you have your three "regular nodes" and 4 text nodes - the linebreaks - resulting in a total of 7 child nodes.
What you instead want is .children.length
or .childElementCount
(not supported in IE<9) to only fetch "actual" nodes:
let temp = document.getElementById('element').parentNode;
console.log(temp.children.length);
// or the following
console.log(temp.childElementCount);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…