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 can you use array with jquery?
What is ajax and how it works?
What is the difference between find and children methods?
What are the advantages of jQuery?
What are the approaches of extracting a query string with regular expressions?
Jquery can be used in what scenarios?
Explain cache paremeter of jquery ajax method?
Tell me can we have multiple document.ready() function on the same page? : jquery mobile
What is jquery toggle function?
What is the use of delegate() method in jquery?
What is slice() method in jquery?
How to write browser specific code using jQuery?