Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    close enough. the method is:
    insertBefore()

    tbodyelem.insertBefore(thenewRow,someRow)
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •