top button
Flag Notify
Site Registration

What is difference between $(this) and ‘this’ in jQuery?

+1 vote
1,188 views
What is difference between $(this) and ‘this’ in jQuery?
posted Jun 19, 2014 by Upma

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

this is the DOM object, whereas $(this) is the jQuery Object.But both are same functionality.

answer Jun 26, 2014 by anonymous
0 votes

Refer the following example

$(document).ready(function(){
$(‘#clickme’).click(function(){
alert($(this).text());
alert(this.innerText);
});
});

-this and $(this) references the same element but the difference is that “this” is used in traditional way but when “this” is used with $() then it becomes a jQuery object on which we can use the functions of jQuery.
-In the example given, when only “this” keyword is used then we can use the jQuery text() function to get the text of the element, because it is not jQuery object. Once the “this” keyword is wrapped in $() then we can use the jQuery function text() to get the text of the element.

answer Jun 20, 2014 by Parampreet Kaur
Similar Questions
+1 vote

Tell me the difference for below two functions

$(document).ready(function() {

    alert("Function using Document Ready");

}

vs

$(function() { 
  alert("Normal function");
}
...