What is returned by jQuery append? -
this partly honest question, partly rant. suppose have html
<ol id="t"></ol>
and jquery code
var x = $('#t').append('test'); var y = x.append('<ol>hello</ol>'); x.append('hello2'); y.append('hello3');
what should expect see? tried here. http://jsfiddle.net/a7j5nw9z/ , appears me append function returns this. in other words x.append('foo') appears return x. checked jquery documentation both here , here. return value undocumented. can safely assume all jquery functions return this unless otherwise documented? documented somewhere? glancing through jquery docs, , lots of functions have undefined return values.
most frequently, use jquery() function create jquery object. jquery() can accessed familiar single-character alias of $(), unless have called jquery.noconflict() disable option. many jquery methods return jquery object itself, method calls can chained:
in api calls return jquery, value returned original jquery object unless otherwise documented api. api methods such .filter() or .not() modify incoming set , return new jquery object.
emphasis mine; , in fact append()
returns jquery
.
Comments
Post a Comment