...

View Full Version : getting getElementById of dynamically added tr



keajav
02-07-2006, 01:00 AM
hi all,

i'm building a tree using ajax to collect nodes by the onClick event to expand a parent node.

the base parent nodes are added via an ajax call and each row is assigned a numerical id.

then, when a parent node is clicked to expand and append the child nodes, I am trying to set the appendChild to the tr of the parent node, but it is coming up as a null.

here's psuedo code of flow:

onload ->
createTable: ajax call to return DS of top-level parent nodes
appendChild(row and cell), specify row id, add a plus button
to expand the children of each row

btn.onClick: ajax call to return DS of child nodes,
var row=document.getElementById(id of row selected)
row.appendChild(child row)

so, the question here is am I able to grab that getElementById of the parent row added in the createTable()?

let me know if you'd like to see the straight code, and thanks.

Kor
02-07-2006, 09:58 AM
numerical id

id must start with a letter, not a number

Why do you need id's?... you may use the index of the rows. And take care, the root to append the rows is not the table element, must be the tbody element, event if you have not created it (and in fact you don't need to create it). Javascript interpertor sees the tbody as a compulsory element of the table.

keajav
02-07-2006, 06:19 PM
i understand your suggestion to use index, and the tbody element. But this leads me to another question. If all rows must be appended to the tbody as their parent node, then how do you insert rows into the middle of a table. I think i have to traverse the table, find the row i need, and the use insertAfter() to append the new rows to the tbody. I'll try that. let me know what you think. and thanks.

Kor
02-08-2006, 08:39 AM
close enough. the method is:
insertBefore()

tbodyelem.insertBefore(thenewRow,someRow)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum