title: Click events inside jQuery plugin
body: <p>I'd like to do something relatively simple with a jQuery plugin. I'm just not totally sure about a click event inside of it.</p>
  
  <p>Here's a simple example that works...</p>
  
  <pre><code>$.fn.testy = function() {
    var testElem = this.find('p');
      testElem.click(function(){
        testElem.addClass('highlighted');
        ^^^^^^^^
     });
  
  };
  
  $("div").testy();
  </code></pre>
  
  <p>Now, if instead of writing <code>testElem.addClass('highlighted');</code>, I put <code>this.addClass('highlighted');</code>, I would get this error: <code>Uncaught TypeError: Object #&lt;HTMLParagraphElement&gt; has no method 'addClass'</code></p>
  
  <p>I understand that <code>this</code> refers to jQuery in this context. I'm making it work by just reusing the variable, but that feels wrong. How do I target the thing that I'm clicking?</p>
  
  <p>For example, if I were just writing a script, I'd write something like this:</p>
  
  <pre><code>$('a').click(function(){
    $(this).addClass('active');
  });
  </code></pre>
  
  <p>How could I do that while targeting only the <code>a</code> elements inside the specified element?</p>