title: using javascript to create a div onclick
body: <p>I'm using pure JavaScript to create a new div element when the user clicks on another div.  Here is my JSFiddle.  No errors being reported, but the div is not being created.  Please help.  Thank you so much!</p>
  
  <p>Basically, this is what I have right now:</p>
  
  <pre><code>document.getElementByID("text").onclick = function () {
      var ok = true;
  };
  
  if (ok === true) {
      var div = document.createElement('div');
      div.style.backgroundColor = "black";
      div.style.position = "absolute";
      div.style.left = "50px";
      div.style.top = "50px";
  }
  
  &lt;div id="text" style="width:20%;height:30px;background-color:blue;"&gt;&lt;/div&gt;
  </code></pre>
  
  <p><a href="http://jsfiddle.net/eMNfd/1/" rel="nofollow">http://jsfiddle.net/eMNfd/1/</a></p>
  
  <p>SOLVED:</p>
  
  <p>Here's my final code:</p>
  
  <pre><code>document.getElementById("text").onclick = function () {
      var div = document.createElement('div');
         div.style.backgroundColor = "black";
         div.style.position = "absolute";
         div.style.left = "50px";
         div.style.top = "50px";
         div.style.height = "10px";
         div.style.width = "10px";
  
         document.getElementsByTagName('body')[0].appendChild(div);
  };
  </code></pre>