Can't Set Innerhtml on Tbody in Ie

Can't set innerHTML on tbody in IE

That is true, innerHTML on tbody elements is readOnly in IE

The property is read/write for all
objects except the following, for
which it is read-only: COL, COLGROUP,
FRAMESET, HEAD, HTML, STYLE, TABLE,
TBODY, TFOOT, THEAD, TITLE, TR.

source: http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx

You can do something like this to work around it:

function setTBodyInnerHTML(tbody, html) {
var temp = tbody.ownerDocument.createElement('div');
temp.innerHTML = '<table>' + html + '</table>';

tbody.parentNode.replaceChild(temp.firstChild.firstChild, tbody);
}

Basically it creates a temporary node into which you inject a full table. Then it replaces the tbody with the tbody from the injected table. If it proves to be slow, you could make it faster by caching temp instead of creating it each time.

Can't set innerHTML on tbody in IE

That is true, innerHTML on tbody elements is readOnly in IE

The property is read/write for all
objects except the following, for
which it is read-only: COL, COLGROUP,
FRAMESET, HEAD, HTML, STYLE, TABLE,
TBODY, TFOOT, THEAD, TITLE, TR.

source: http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx

You can do something like this to work around it:

function setTBodyInnerHTML(tbody, html) {
var temp = tbody.ownerDocument.createElement('div');
temp.innerHTML = '<table>' + html + '</table>';

tbody.parentNode.replaceChild(temp.firstChild.firstChild, tbody);
}

Basically it creates a temporary node into which you inject a full table. Then it replaces the tbody with the tbody from the injected table. If it proves to be slow, you could make it faster by caching temp instead of creating it each time.

IE: Invalid target element - appending table using innerHTML + string

Yes you will need to wrap them first like this:

var div = document.createElement("div");
div.innerHTML = "<table><tbody>" + string + "</tbody></table>";

document.getElementById("left")
.appendChild(div.firstChild.tBodies[0]);

Cannot set property 'innerHTML' of null

You have to place the hello div before the script, so that it exists when the script is loaded.



Related Topics



Leave a reply



Submit