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 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    insert element at specified position DOM2

    I have scenario like below, in table we have insert row & in row we
    have insert cell, but i need to insert an table element in td,


    Here in td i have tbl1 & tbl2 as child and now i want to insert tbl0 as
    first child (before the tbl1)


    var tbl=document.createElement('TABLE');
    var tr=tbl.insertRow();
    tr.id='tr';
    var td=tr.insertCell();
    td.id='td';
    var tbl1=document.createElement('TABLE');
    tbl1.id='tbl1';
    td.appendChild(tbl1);
    var tr1=tbl1.insertRow();
    var td1=tr1.insertCell();
    td1.innerText='abc';
    var tbl1=document.createElement('TABLE');
    tbl1.id='tbl2';
    td.appendChild(tbl1);
    var tr1=tbl1.insertRow();
    var td1=tr1.insertCell();
    td1.innerText='cde';
    document.body.appendChild(tbl);
    td=document.getElementById('td1');


    var tbl1=document.createElement('TABLE');
    tbl1.id='tbl0';
    td.appendChild(tbl1);
    var tr1=tbl1.insertRow();
    var td1=tr1.insertCell();
    td1.innerText='xyz';


    //how to insert the above table tbl0 in td as first child

  • #2
    New Coder
    Join Date
    Oct 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanx, i achieved with insertBefore


  •  

    Posting Permissions

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