Method chaining works off the return value of the previous method.
var chain = {
example: function (val) {
alert(val);
return this;
}
};
chain.example('this').example('works');
example
can be chained off of example
because return this
returns an object which has an example
method.
In the case of parent.appendChild(child)
the return value is child
, which means that chaining will not add elements to parent
further, instead subsequent elements will be nested.