Monday, December 1, 2008

Setting innerHTML gives error in IE





innerHTML ::


The innerHTML property reflects the content contained by the referenced element, including all the HTML elements.

For example, consider the following <DIV> element:


<DIV ID="Address1">

Shiv Prasad,<BR>

1, Rajendra Babu Road,<BR>

Wadala,<BR>

Mumbai, India

</DIV>


The address' innerHTML property (obtained by referencing it via its ID property) would be:
Shiv Prasad,<BR>
1, Rajendra Babu Road,<BR>
Wadala,<BR>
Mumbai, India .



The innerHTML property has read-write permissions, meaning that HTML content can be 'written' into any element through scripting, with the document being re-displayed accordingly, dynamically re-positioning surrounding document content. The new HTML content would adopt whatever stylings (and ID) were applied to the referenced element, before the new content was supplied.


However innerHTML property works for all objects except the following, for which it is read-only: COL, COLGROUP, FRAMESET, HEAD, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR. I checked with couple of browsers, and found IE is the most problematic. IE gives error and halts the execution of javascript if you try to set innerHTML property for above said elements. Works fine with mozilla firefox & safari though. This is one more reason why Microsoft should look for the products with better quality.



No comments: