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 parent() in jquery?
Is there any difference between body onload() and document.ready() function?
Mention the advantages of cdn? : jQuery Mobile
How to include jquery library in asp.net project?
Define cdn in jquery?
Is jquery a framework?
How we can hide a block of html code on a button click using jquery?
What is the goal of cdn and what are the advantages of using cdn?
Why do we use jquery? : jquery mobile
How does the jQuery pushStack function work?
What is the difference between jquery-x.x.x.js and jquery.x.x.x min.js?
What is the jQuery code to select all links inside the paragraph?