javascript - Where did the old object go? -
i've implemented routine sort xhtml table in place based on (= more or less copied from) nicholas c. zakas, professional javascript web developers, ch. 12. works advertised, have few questions how code works , grateful advice. here relevant bits:
var oldtable = document.getelementbyid('mytable'); var oldtablebody = oldtable.tbodies[0]; var oldtablerows = oldtablebody.rows; var newtablearray = new array(); (var = 0, rowcount = oldtablerows.length; < rowcount; i++) { newtablearray.push(oldtablerows[i]); } newtablearray.sort(choosesort); var newfragment = document.createdocumentfragment(); (var = 0, rowcount = newtablearray.length; < rowcount; i++) { newfragment.appendchild(newtablearray[i]); } oldtablebody.appendchild(newfragment);
i understand i'm adding pointers existing table rows when push new values onto newtablearray
, i'm not sure how appendchild
methods work. specifically:
when append each of array items (pointers original rows) document fragment, adding pointer (leaving row still in original table), or removing row object original table appending somewhere else?
when append
newfragment
oldtablebody
, if understand correctly, i'm appending not fragment object, row objects i've appended it, , that's way fragments work. correct?when append
newfragment
oldtablebody
, don't explicit remove rows there. did go? appending them anew automatically remove old traces of them because can attached once? if i'm working pointers, , not objects (which thought let me attach themnewtablearray
without automatically making them disappear table), mean can have multiple pointers same object in cases (oldtable
plusnewtablearray
) not others (original rows in original table plus new, sorted rows i'm adding)?
apologies naive questions, although getting results want satisfying, not understanding how code works makes me uneasy.
i think questions boil down asking appendchild
does. removes element in dom , places same element in new spot.
Comments
Post a Comment