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 |
What is jQuery.noConflict?
In what situation you would use multiple version of jQuery and how would you include them?
Tell me does jquery 2.0 supports ie? : jquery mobile
Differences Between jQuery .bind() and .live()?
List a few features of jquery mobile? : jQuery Mobile
Tell me how do you stop the currently-running animation? : jquery mobile
Explain the features of jquery?
What is the purpose of fadetoggle() method in jquery?
Back onto jquery ui' can you see jquery ui making more of an impression in the future, lead by the current successes of jquery?
Define the script build up by jquery?
What is wrong with this code line "$('#myid.3').text('blah blah!!!');"
Tell me how to executed jquery selectors? : jquery mobile