title: add an onclick event to a div
body: <p>I don't know if this is allowed or even possible. Is it possible to create a div element with an onclick event so that if anywhere in the div's area is clicked, the event will run.</p>
  
  <p>Eg
  JAVASCRIPT:</p>
  
  <pre><code>var divTag = document.createElement("div");
  divTag.id="new-ID"; 
  var onClickCommand = "printWorking()"   //printworking is another method that simply print "I'm working" to the console
  divTag.onclick = onClickCommand;
  console.log("onclick command added");
  console.log(divTag.onclick);
  parentDiv.appendChild(divTag); //This simply adds the div tag to the page.
  </code></pre>
  
  <p>HTML generated:</p>
  
  <pre><code> &lt;!--&lt;div id="new-ID"&gt;--&gt;
  
   whatever content I decide to add to the divTag.innerHTML
  </code></pre>
  
  <hr>
  
  <p>I notice how theres no onclick command going through to the generated div. Id this because its not allowed?</p>
  
  <p>So 2 questions then.</p>
  
  <p>1:Is it possible to add onclick to a div and have it occur if any area of the div is clicked.
  2:If yes then why is the onclick method not going through to my div.</p>
  
  <hr>
  
  <p>How very odd:</p>
  
  <pre><code>divTag.setAttribute("onclick", "printWorking()");
  </code></pre>
  
  <p>Above works flawlessly.</p>
  
  <p>All below don't and wont pass the onclick to the div.</p>
  
  <pre><code>divTag.onclick=printWorking;
  
  divTag.onclick="printWorking";
  
  divTag.onclick="printWorking()";
  </code></pre>
  
  <p>Multiple other variants have been tried too.</p>