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

What is jQuery.noConflict?

1 Answers  


In what situation you would use multiple version of jQuery and how would you include them?

1 Answers  


Tell me does jquery 2.0 supports ie? : jquery mobile

0 Answers  


Differences Between jQuery .bind() and .live()?

0 Answers  


List a few features of jquery mobile? : jQuery Mobile

0 Answers  






Tell me how do you stop the currently-running animation? : jquery mobile

0 Answers  


Explain the features of jquery?

0 Answers  


What is the purpose of fadetoggle() method in jquery?

0 Answers  


Back onto jquery ui' can you see jquery ui making more of an impression in the future, lead by the current successes of jquery?

0 Answers  


Define the script build up by jquery?

0 Answers  


What is wrong with this code line "$('#myid.3').text('blah blah!!!');"

1 Answers  


Tell me how to executed jquery selectors? : jquery mobile

0 Answers  


Categories