title: Passing a reference to an element without assigning an id
body: <p>I would like several elements to use the same onclick handler, so I have:</p>
  
  <pre><code>function close_div() {
      $(this).remove();
  }
  
  &lt;div class="closeX" onclick="close_div()"&gt;The first div&lt;/div&gt;
  &lt;div class="closeX" onclick="close_div()"The second div&lt;/div&gt;
  &lt;div class="closeX" onclick="close_div()"The third div&lt;/div&gt;
  </code></pre>
  
  <p>So when you click any div it gets removed from the DOM.</p>
  
  <p>The problem with the code above is that onclick doesn't pass a useful this keyword so close_div() can't use it.  If I gave each <code>div.closeX</code> a different <strong>id</strong> I could pass that as <code>close_div(id)</code> and do something like   <code>$("#"+id).remove()</code>.  But it seems like there should be a way to automatically pass a reference to the element that was clicked, without assigning an id to the element and passing that.  Am I missing something?</p>
  
  <p>Thanks</p>