title: who am I - JQuery, Plugin, $this, $(this), this, access to variable
body: <p>I have a problem with identify the object that runs the function</p>
  
  <pre><code>&lt;div id="test1"&gt;lorem&lt;/div&gt;
  &lt;div id="test2"&gt;ipsum&lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
      $(document).ready(function() {
          $('#test1').plugin(); //alert: I am test1
          $('#test2').plugin(); //alert: I am test2
  
          $('#test1').plugin.fun(); //alert: I am undefined and I am undefined
          $('#test2').plugin.fun(); //alert: I am undefined and I am undefined
      });
      (function($) {
          $.fn.plugin = function() {
              $this = $(this);
              alert('I am '+$(this).attr('id'));//&lt;-- it works
          }
          $.fn.plugin.fun = function() {
              alert('I am '+$(this).attr('id')); //&lt;-- doesn't work!
              alert('and I am '+$this.attr('id')); //&lt;-- also doesn't work!
          }
      })(jQuery);
  &lt;/script&gt;
  </code></pre>