title: Pass 'div' element as parameter to JavaScript function
body: <p>I need to create, decorate and append child 'divs' to existing. For example, after the appendChildren is executed, following divs</p>
  
  <pre><code>    &lt;div id="a"&gt;
        &lt;div id="b"&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>should take the following form (assuming decorateDiv adds text "This is new div" inside new div)</p>
  
  <pre><code>    &lt;div id="a"&gt;
        &lt;div id="b"&gt;
          &lt;div&gt;"This is new div"&lt;/div&gt;
        &lt;/div&gt;
        &lt;div&gt;"This is new div"&lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Here is my code</p>
  
  <pre><code>    function appendChildren() {
      var allDivs = document.getElementsByTagName("div");
      for (var i = 0; i &lt; allDivs.length; i++) {
      var newDiv = document.createElement("div");
      decorateDiv(newDiv);
      allDivs[i].appendChild(newDiv);
      }
      }
  
  
      function decorateDiv(div) {
        var x = document.getElementByTagName("div");
        var t = document.createTextNode("This is new div");  
      x.appendChild(t); 
      }
  </code></pre>
  
  <p>I am completely new to JavaSpript. What am I doing wrong? Please help me to fix bugs</p>