By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,341 Members | 1,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,341 IT Pros & Developers. It's quick & easy.

insert element at specified position DOM2

P: n/a
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

Dec 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Thanx, i achieved with insertBefore

Dec 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.