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 |
Why we use jquery .each() function?
Can we call c# codebehind method using jquery?
Why is not dom ready working for jquery mobile? : jquery mobile
Define jquery $.ajax() method?
Write the code to define a requirejs module with its dependencies.
Why jQuery is better than JavaScript?
How to add a class to html element?
Difference between javascript and jquery?
Explain the each() function?
Can we have multiple document.ready() function on the same page?
Why are not some scripts and styles loading? : jquery mobile
Explain .live()? : jquery mobile