A jQuery object usually contains a collection / array of DOM nodes. For example, if you iterate over a jQuery object, for example -
$('div').each(function() { //In this context, this refers to the DOM node //and $(this) refers to a jQuery object for that particular DOM node //therefore $(this)[0] == this this.innerHTML = 'foo'; $(this).html('foo'); $(this)[0].innerHTML = 'foo'; });
You can also use . get () for a similar effect.
//retrieves an array of native DOM nodes using jQuery var allDivNodes = $('div').get(); //retrieves the first node retrieved by the selector var firstDiv = $('div').get(0); //this is the same as get(0), however, using an array accessor can throw an exception var firstDiv = $('div')[0];
source share