How to traverse all of the peer nodes

var el = document.getElementById('div1').firstChild;

while (el !== null) {
  console.log(el.nodeName);
  el = el.nextSibling;
}

Principle: Use the Node.prototype.nextSibling return null sibling nodes at the time of acquisition is less than the back of this feature.

Guess you like

Origin www.cnblogs.com/aisowe/p/11505902.html