Let's say we have :
$("p")[0].innerHTML;
and
$("p").html();
In the above examples, we have the same result. So I was wondering how can JQuery return both the nodelist and itself to allow chaining ?
So I was wondering how can JQuery return both the nodelist and itself to allow chaining ?
It doesn't.
It only returns itself (which it an object).
That object has a property called 0 which contains the first element in the array of elements. It also has a property called html which contains a function.
0. An array is just an object which inherits some properties along the prototype chain from Array and is designed to hold data using properties with integer values as their names.$("p")["0"].innerHTML also works which I just tested and yes, it has a number property for each "array" entry. Thanks for that little titbit. My ignorance has lessened +1 :)
htmland0. If youconsole.log($('p'))you'll see all the methods listed.console.log($("p"));andconsole.log($("p")[0]);you will understand.