Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-07-2006, 01:00 AM   PM User | #1
keajav
New to the CF scene

 
Join Date: Jan 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
keajav is an unknown quantity at this point
getting getElementById of dynamically added tr

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.
keajav is offline   Reply With Quote
Old 02-07-2006, 09:58 AM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
Quote:
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.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 02-07-2006, 06:19 PM   PM User | #3
keajav
New to the CF scene

 
Join Date: Jan 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
keajav is an unknown quantity at this point
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.

Last edited by keajav; 02-07-2006 at 07:15 PM..
keajav is offline   Reply With Quote
Old 02-08-2006, 08:39 AM   PM User | #4
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
close enough. the method is:
insertBefore()

tbodyelem.insertBefore(thenewRow,someRow)
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:03 PM.


Advertisement
Log in to turn off these ads.