Copy the content of one table into another
11,242
Internet Explorer doesn't let you edit the inside of tables with innerHTML - it is all or nothing.
Since you are trying to use innerHTML to copy the information, a complete copy should be safe (i.e. not have any id attributes that might become duplicated), in which case I would do this:
var source = document.getElementById('tableA');
var destination = document.getElementById('tableB');
var copy = source.cloneNode(true);
copy.setAttribute('id', 'tableB');
destination.parentNode.replaceChild(copy, destination);
Author by
SvenFinke
Updated on June 04, 2022Comments
-
SvenFinke almost 2 years
In my current application i need to copy the content of one table into another... With setting innerHTML it works perfectly in FF... but not in IE8... Here is the Code i used to copy in FF:
getID("tableA").innerHTML = getID("tableB").innerHTML; // getID is a custom function i wrote to provide a shorter version of document.getElementById();
TableA is empty (only the tbody tag exists). TableB is looking like this:
table tbody tr td "Content" /td td "Content" /td /tr /tbody /table
I already tried using nodeValue.. or appendData... or outerHTML.. but nothing really worked...