title: What is root node in javascript
body: <p>Why we use root node. In below given function they use root node function. I want to understand this function also what is meaning of '!rootNode'.</p>
  
  <pre><code> function getElementsByClassName(cn, rootNode) {
    if (!rootNode) {
      rootNode = document;
    } 
    for (var r=[], e=rootNode.getElementsByTagName('*'), i=e.length; i--;) {
      if ((' '+e[i].className+' ').indexOf(' '+cn+' ')&gt;-1) {
        r.push(e[i]); 
      }
    }
    return r;  
  }
  </code></pre>