title: How can I find the element clicked on inside a jQuery handler?
body: <p>I'm trying to do a specific action on the clicked element if an argument is passed in the on click method in jQuery. When I try to access <code>this</code> it's referencing the entire window instead of the clicked on element. How would I access the clicked on element in the handler?</p>
  <p>Here's the code I'm using:</p>
  <pre><code>var myfunction = function(action) {
    var content;
    var $this = $(this);
  if(action === &quot;one&quot;) {
    $(&quot;.output&quot;).text(&quot;clicked on one&quot;);
    $this.addClass(&quot;one&quot;);
   } 
  if(action === &quot;two&quot;) {
   $(&quot;.output&quot;).text(&quot;clicked on two&quot;);
   $this.addClass(&quot;two&quot;);
    }
  };
  $(&quot;#button&quot;).on(&quot;click&quot;, function(event) {
   myfunction(&quot;one&quot;);
  });
  
  $(&quot;#button2&quot;).on(&quot;click&quot;, function(event) {
    myfunction(&quot;two&quot;);
  });
  </code></pre>
  <p>I set up an example on jsbin <a href="http://jsbin.com/bipafi/edit?html,js,output" rel="nofollow noreferrer">here</a>. Any help would be appreciated.</p>