PDA

Click to See Complete Forum and Search --> : appendChild in descending order


tr0n
Nov 26th, 2002, 10:12 AM
on a webpage, i've got some javascript that will append rows to a table dynamically when the user clicks a button. currently, this does it in ascending order (ie. items get added to the bottom of the table), but i was wondering if it's possible to make it add rows in descending order (ie. items get added to the top of the table)?

this is the code i'm using:

tbody = document.getElementById(objectid).getElementsByTagName("TBODY")(0);
row = document.createElement("TR");
cell1 = document.createElement("TD");
cell2 = document.createElement("TD");
cell3 = document.createElement("TD");
chk = document.createElement("INPUT");

cell1.bgColor = "#dfdfdf";
cell2.bgColor = "#f1f1f1";
cell2.align = "right";
cell3.bgColor = "#dfdfdf";
cell3.align = "center";
chk.type = "checkbox";
cell1.appendChild(document.createTextNode("Blah"));
cell2.appendChild (document.createTextNode("Bleh));
cell3.appendChild (chk);
row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
tbody.appendChild(row);

i found some code that will allow you to click a column in a table that'll dynamically sort it, so i guess this should be possible somehow.

can anyone help?