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 is a filter in jquery? Explain
How can you apply a style on an element using jQuery?
How can events be prevented from stopping to work after an ajax request?
How can we apply css in div using jquery?
What is a jquery library?
Define cache paremeter of jquery ajax method?
How to check jQuery version?
Define url paremeter of jquery ajax method?
Please explain remove class jquery with example?
What is queue() in jquery?
What were the biggest challenges of getting the jQuery 1.7 release ?
How to select combobox select value and text using jquery?
Can you give me a brief history of your programming days? Where did it all start?
Explain width() vs css(‘width’)?
Explain all the ways to include jquery in a page?