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 |
What is the use of val() method in jquery?
Can you write a jquery code to select all links inside the paragraph?
Mention the advantages of cdn? : jQuery Mobile
Explain the use of the .pushstack() method.
Explain data paremeter of jquery ajax method?
Is jQuery is a JavaScript or JSON library file?
Explain the concepts of "$ function" in jquery with an example?
Tell me how to check data type of any variable in jquery? : jquery mobile
Explain deferred and promise object in jquery? : jquery mobile
What are the advantages of using cdn?
Tell me how to use migrate jquery plugin if possible? : jquery mobile
How is body onload() function is different from document.ready() function used in jquery?