The following method creates a table and attaches it to the DOM tree, but it is not displayed in IE:
VaR table = Document. createelement ("table ");
VaR TR = Document. createelement ("TR ");
VaR TD = Document. createelement ("TD ");
VaR text = Document. createtextnode ("text ");
TD. appendchild (text );
Tr. appendchild (TD );
Table. appendchild (TR );
Document. Body. appendchild (table );
No error is reported. You can also see that the entire table is completely created and attached to the body, but it is not displayed. This is because TR is not allowed to be directly appended to the table in IE. Instead, you must first attach tr to the tbody and then attach the tbody to the table. So the correct one should be:
VaR table = Document. createelement ("table ");
VaR tbody = Document. createelement ("tbody ");
VaR TR = Document. createelement ("TR ");
VaR TD = Document. createelement ("TD ");
VaR text = Document. createtextnode ("text ");
TD. appendchild (text );
Tr. appendchild (TD );
Tbody. appendchild (TR)
Table. appendchild (tbody );
Document. Body. appendchild (table );
This problem does not exist in Firefox. Note that tbody elements are not mandatory when a table is constructed using HTML explicitly. Maybe IE will automatically add tbody during parsing. Otherwise, the explanation will fail?