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 |
Tell me what are the slow selectors in jquery? : jquery mobile
Which is the fastest selector in jQuery?
Can we execute/run multiple Ajax request simultaneously in jQuery? If yes, then how?
How can you disable jquery animation?
Can we have multiple document.ready() function on the same page?
Is jQuery a W3C standard?
How does caching helps and how to use caching in jQuery?
How does the jQuery pushStack function work?
Differentiate between width() vs css(‘width’) in jquery
Is jquery a w3c standard? : jquery mobile
Do you know what is the use of jquery.data()?
How can you get the type of arguments passed to a function?