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
Define all the ways to include jquery in a page?
differentiate between bind() vs live() vs delegate() methods in jquery.
How to validate email using jquery?
What is the difference between "#" and "." selector in JQuery?
Explain the difference between onload() and document.ready() function used in jquery?
Is jquery a w3c standard? : jquery mobile
What is the difference between $(window).load and $(document).ready function in jquery?
Explain cache paremeter of jquery ajax method?
Create a plugin that would add and remove a class on hover.
How do I pull a native DOM element from a jQuery object?
Can we include multiple version of jquery? : jquery mobile
What is a use of jquery filter?
How can jquery library be added to pages? Write a basic jquery code?
How to find all sibling elements after the current element using ?
Explain the difference between .empty() and .remove() ?