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 the goal of cdn and what are the advantages of using cdn?
Explain width() vs css(‘width’)?
How to use transition effects? : jQuery Mobile
How to executed jquery selectors? : jquery mobile
Is numeric in jquery?
How to revert the most recent ‘destructive’ operation, changing the set of matched elements to its previous state using ?
How you get server response from an ajax request using jquery?
Define url paremeter of jquery ajax method?
How to add or remove classes to an element in jquery?
What is the purpose of jquery?
Explain the difference between find and children methods in jquery?
Explain the common methods of sending a request to a server.
What is ajax and how it works?
Explain the each() function?
How does jquery mobile theming work? : jquery mobile