title: Alert ID of current element
body: <p>I'm using following code to alert id of current element.</p>
  
  <pre><code>&lt;input type="text" id="desc" name="txtTitle" onclick="fun()"&gt;
  </code></pre>
  
  <p>jquery:</p>
  
  <pre><code>function fun () {
      var currentId = $(this).attr('id');
      alert(currentId);
  }
  </code></pre>
  
  <p>Why does it alert "undefined"?
  I have tried with: </p>
  
  <pre><code>var currentId =$('element').attr('id'); 
  // and 
  alert($(this).id); 
  // and 
  alert(this.id);
  </code></pre>
  
  <p>but it alerts <code>undefined</code></p>