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 ?
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.
that is called fluent syntax. each function returns the object it is given. something like
function f(obj){
doSomething(obj);
return obj;
}