title: Javascript: Setting onclick dynamically and passing in the element itself
body: <p>I'm dynamically creating some <code>&lt;div&gt;</code> elements and then filling their <code>innerHTML</code> properties with text. I'm trying to set their <code>onclick</code> event handlers like this:</p>
  
  <pre><code>myDiv.onclick = function() { alert("Hello!") };
  </code></pre>
  
  <p>That I can do. What I would like to do is be able to access the value / innerHTML (new to Javascript and DOM, so I'm unsure of what term is what I'm looking for) within the newly defined <code>onclick</code> function. How would I go about accessing the data of <code>myDiv</code> within the function being defined for its <code>onclick</code> property? <code>myDiv</code> will be something simple like:</p>
  
  <pre><code>&lt;div&gt;StackOverflow&lt;/div&gt;
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>