Share:
       
   

$(this) returns a jQuery object, on which you can call several jQuery methods e.g. text() to retrieve text, val() to retrieve value etc, while this represent current element, and it’s one of the JavaScript keyword to denote current DOM element in a context. You can not call jQuery method on this, until it’s wrapped using $() function i.e. $(this).

Example:

$(document).ready(function(){
    $('#DivValue').mouseover(function(){
       alert($(this).text());
  });
});

////**************////

$(document).ready(function(){
    $('#DivValue').mouseover(function(){
       alert(this.innerText);
  });
});

About Raka Rocks

Hi, My self Raka Rocks. I am web designer and Front End Developer total 8 year exp. in this fields. I am a continuous blogger and has blogged on different topics. He loves to surf the Internet and always tries to get new ideas about new technologies and innovations and share this excellent information with all technology lovers.

2 thoughts on “Difference between $(this) and this keyword in jQuery?

Leave a Reply

Your email address will not be published.