...

View Full Version : insert element at specified position DOM2



sudhakar_jr
12-13-2005, 10:21 AM
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

sudhakar_jr
12-13-2005, 11:04 AM
Thanx, i achieved with insertBefore



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum