Q&A
Ask and answer questions to make information more available to wider audiences.
Chandler Bal @balchandler   04, Jul 2023 12:00 AM
difference between $(this) and this
In jQuery, what is the difference between $(this) and this?
answers 1
 
Answer 1
Uriah Chapman @chapmanuriah   07, Jul 2023 04:34 PM
$(this) is a jQuery object, whereas this is a JavaScript global object reference. We may refer to DOM elements in HTML documents using this.
$(this) refers to the parent object, whereas this is a DOM element that, in the case of an array, represents an object with the .each() method, which shows the current iteration.
We use this as an alternative to this.parent() to refer to the parent object in JavaScript. This is more convenient than using this.parent(). We can also use this to refer to other elements in HTML, as in an ul element: 

var myElement = $('ul').each(function() { 
    var childElement = this.parent().nextSibling(); 
}); 
This is useful when you need to iterate over a list of elements and their children, but you do not want to reference the parent object.