Answer Posted / 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 |
Post New Answer View All Answers
What are the methods used to provide effects?
Why we use chaining in jquery?
what is the use of param() method in jquery .
What programming language does jquery use?
Why content injected into a page is not enhanced? : jquery mobile
Which operating system is more compatible with jQuery?
What is the use of val() method in jquery?
Is jquery is json library file or a javascript?
What are the slow selectors in jquery? : jquery mobile
How does the jQuery pushStack function work?
How can events be prevented to work after an ajax request?
How can jquery be used in conjunction with another javascript library that also uses $ for naming?
What is the difference between the knockout and jquery?
What is a filter in jquery? Explain
What's next on the hitlist with jquery ui?