Live DOM nodes

Maybe I am just naive, but I am used to jQuery’s static node, meaning the change in the DOM structure is not reflected automatically in a queried result.

It turns out some native methods are live or reactive. Three of them are:
document.getElementsByTagName()
document.getElementsByTagNameNS()
document.getElementsByClassName()

This means the following code is an infinite loop:

var divs = document.getElementsByTagName('div');
for(var i=0; i<divs.length; i++){
  document.body.appendChild(document.createElement('div'));
}
Advertisements
Standard