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 use css() in jquery?
What is .empty()? : jquery mobile
What is the difference between $(window).load and $(document).ready?
Is jquery library used for server scripting or client scripting?
What were the biggest challenges of getting the 1.7 release out there?
Tell me can we have multiple document.ready() function on the same page? : jquery mobile
What is a jquery ?
Tell me how to select combobox select value and text using jquery?
Define data paremeter of jquery ajax method?
How to redirect to another page using jquery?
How to debug jquery code/ debug jquery?
Have any of your startup projects failed dismally - if so, why and how did you learn from them?