Possible Duplicate:
jQuery $(this) vs this
I’m new to this and trying to get my concept right. There has been many instances of the use of “this” and “$(this)“. Can someone please explain the difference and in what condition that we use the two different “this”?
In jQuery functions,
thismost often refers to the actual DOM element you’re dealing with, whereas$(this)returns a jQuery object that wraps the element.In JavaScript,
thisalways refers to the current scope. Many of jQuery’s functions will set that scope to be the element you’re working with.For instance
The point is, that the jQuery object has all the jQuery functions (like
.detatch()or.prependTo()etc.), while the DOM element is what the browser provides. In the example above, the element would be exactly the same as what you’d get, if you calleddocument.getElementById("someElement")