IE6-IE9 does not support table. innerHTML Solutions

Source: Internet
Author: User
Let the ie6-ie9 support table. innerHTML, in fact, this is just the processing of the table, the other unsupported elements can use a similar solution to test the Code:

The Code is as follows:




Script
Var oTable = document. getElementById ("test ");
OTable. innerHTML ="InnerHTML";
Script



The above Code does not work in the IE6-9 and an error is reported directly:
IE9: Invalid target element for this operation.
IE6-8: Unknown runtime error
Find the IE document (http://msdn.microsoft.com/en-us/library/ms533897 (VS.85). aspx) and find such a paragraph:

The InnerHTML Property is read-only on Col, ColGroup, FrameSet, Html, Head, Style, Table, TBody, TFoot, THead, Title, And Tr Objects.

So we can only use other solutions. My solutions:

The Code is as follows:


Var oTable = document. getElementById ("test ");
// OTable. innerHTML ="InnerHTML";
SetTableInnerHTML (oTable ,"InnerHTML");

Function setTableInnerHTML (table, html ){
If (navigator & navigator. userAgent. match (/msie/I )){
Var temp = table. ownerDocument. createElement ('P ');
Temp. innerHTML ='

'+ Html +'
';
If (table. tBodies. length = 0 ){
Var tbody = document. createElement ("tbody ");
Table. appendChild (tbody );
}
Table. replaceChild (temp. firstChild. firstChild, table. tBodies [0]);
} Else {
Table. innerHTML = html;
}
}


Here, we only process the table and use a similar solution for other unsupported elements.

In addition, table in IE10 supports innerHTML.

Author: Artwl

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.