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 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    dynamically appending child at a specified position....?

    Hi

    i want to dynamically add rows to my table body using javascript, which am able to do. but there is a problem.

    for ex.
    three rows
    1
    2
    3

    if i delete second row
    1
    3
    if i want to add one more row.., then it should be row 2 with number 2.
    ---------------------------------------------
    var totChkTable = document.getElementById('TABLE');
    row=totChkTable.tBodies[0].appendChild(document.createElement('<tr >'));
    ..
    ....
    cell=document.createElement('td');
    ---------------------------------------------

    In each row ther r 6 colums, so i need a way where i can append my child in b/w.

    thnx
    murali

  • #2
    New Coder
    Join Date
    Nov 2006
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can use the insertBefore() method.
    Code:
    var totChkTable = document.getElementById('TABLE');
    var rows = totChkTable.getElementsByTagName('tr');
    totChkTable.tBodies[0].insertBefore(document.createElement('tr'),rows[1]);
    Last edited by j9ine; 12-28-2006 at 07:07 PM.


  •  

    Posting Permissions

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