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 |
How to check if number is numeric while using jQuery 1.7+?
List browser related issues for jquery?
Is it possible to get value of multiple CSS properties in single statement?
Back onto jquery ui' can you see jquery ui making more of an impression in the future, lead by the current successes of jquery?
Explain jquery.noconflict? : jquery mobile
What are the advantages of method chaining in jquery?
What is the jQuery code to select all links inside the paragraph?
Is jQuery is a client or server scripting?
Can we execute/run multiple Ajax request simultaneously in jQuery? If yes, then how?
Is jQuery a programming language?
What is jQuery CDN?
What are all the ways to include jQuery in a page?