Difference between $(this) and ‘this’ in jQuery

this and $(this) refers to the same element. The only difference is the way they are used. ‘this’ is used in traditional sense, when ‘this’ is wrapped in $() then it becomes a jQuery object, and you are able to use the power of jQuery.

Check below examples for this and $(this) understanding:

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

//And

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

Check More on jQuery

Leave a Reply

Your email address will not be published. Required fields are marked *