Internet Explorer (IE) friendly table DOM manipulation

Occasionaly we can manipulate HTML DOM easily by accessing the innerHTML of an element. In IE however, the following elements’ innerHTML are read only: COL, COLGROUP, FRAMESET, HEAD, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR.

This code will fail in IE

1
tBodyEl.innerHTML = '<tr height="24px"><td colspan="7">' + 'Some Cell Value' + '</td></tr>';

A more IE friendly solution using DOM table functions.

1
2
3
4
5
var row = tBodyEl.insertRow(0);
row.setAttribute('height', '24px');
var cell = row.insertCell(0);
cell.setAttribute('colspan', '7');
cell.innerHTML = 'Some Cell Value';
This entry was posted in javascript, Web Development. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


five × = 20