Difference between $(this) and 'this' in jQuery?



Difference between $(this) and 'this' in jQuery?..

Answer / chaitanya

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.

Hide Copy Code

$(document).ready(function(){

$('#spnValue').mouseover(function(){

alert($(this).text());

});

});

In below example, this is an object but since it is not wrapped in $(), we can't use jQuery method and use the native JavaScript to get the value of span element.

Hide Copy Code

$(document).ready(function(){

$('#spnValue').mouseover(function(){

alert(this.innerText);

});

});

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More jQuery Interview Questions

Tell me what are the slow selectors in jquery? : jquery mobile

0 Answers  


Which is the fastest selector in jQuery?

0 Answers  


Can we execute/run multiple Ajax request simultaneously in jQuery? If yes, then how?

1 Answers  


How can you disable jquery animation?

0 Answers  


Can we have multiple document.ready() function on the same page?

1 Answers  






Is jQuery a W3C standard?

2 Answers  


How does caching helps and how to use caching in jQuery?

1 Answers  


How does the jQuery pushStack function work?

0 Answers  


Differentiate between width() vs css(‘width’) in jquery

0 Answers  


Is jquery a w3c standard? : jquery mobile

0 Answers  


Do you know what is the use of jquery.data()?

0 Answers  


How can you get the type of arguments passed to a function?

0 Answers  


Categories