From: Hans-Georg Michna on
On Fri, 5 Feb 2010 11:44:32 -0800 (PST), sil wrote:

>I followed your advise. That is, generating the whole string and then
>writing it only once to the innerHTML. It worked beautifully.

It may still not always work, because Internet Explorer cannot
insert certain table-related tags through innerHTML. Citation
from
http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx :

----- Begin Citation -----

innerHTML Property

Sets or retrieves the HTML between the start and end tags of the
object.

Syntax

HTML - N/A
Scripting - [ sHTML = ] object.innerHTML

Possible Values

sHTML - String that specifies or receives the content between
the start and end tags.

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. The property has
no default value.
....
----- End Citation -----

Note the HTML elements in the last paragraph. Even if innerHTML
works for you now, it may fail always or under certain unknown
conditions in all versions of Internet Explorer. So I can only
underwrite what Thomas already wrote:

"You should also avoid `innerHTML', especially with tables; use
DOM creator and mutator methods instead."

Hans-Georg
From: Thomas 'PointedEars' Lahn on
Hans-Georg Michna wrote:

> sil wrote:
>> I followed your advise. That is, generating the whole string and
>> then writing it only once to the innerHTML. It worked beautifully.
>
> It may still not always work, because Internet Explorer cannot
> insert certain table-related tags through innerHTML. Citation
> from
> http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx :
> [...]
> 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. The property has
> no default value.
> ...
> ----- End Citation -----
>
> Note the HTML elements in the last paragraph. Even if innerHTML
> works for you now, it may fail always or under certain unknown
> conditions in all versions of Internet Explorer.

ISTM you are misinterpreting. The paragraph above indicates that writing a
TABLE element into another element using `innerHTML', as the OP does, is
never going to fail in any version of Internet Explorer. Attempting to
write other elements into a TABLE element, however, is bound to fail there.

So there really is no reason for FUD like "it may fail always or under
certain unknown conditions"; the conditions under which it is going to fail
are well-documented.

> So I can only underwrite what Thomas already wrote:
>
> "You should also avoid `innerHTML', especially with tables; use
> DOM creator and mutator methods instead."

I stand by my recommendation. Your argument is a non sequitur, though.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
From: Hans-Georg Michna on
On Sun, 07 Feb 2010 16:46 +0100, Thomas 'PointedEars' Lahn
wrote:

>Hans-Georg Michna wrote:

>> It may still not always work, because Internet Explorer cannot
>> insert certain table-related tags through innerHTML. Citation
>> from
>> http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx :
>> [...]
>> 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. The property has
>> no default value.
>> ...
>> ----- End Citation -----
>>
>> Note the HTML elements in the last paragraph. Even if innerHTML
>> works for you now, it may fail always or under certain unknown
>> conditions in all versions of Internet Explorer.

>ISTM you are misinterpreting. The paragraph above indicates that writing a
>TABLE element into another element using `innerHTML', as the OP does, is
>never going to fail in any version of Internet Explorer. Attempting to
>write other elements into a TABLE element, however, is bound to fail there.

The text is not an absolutely clear definition: "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."

You are saying that it means that innerHTML is read-only if it
is used as the property of one of the above HTML elements? And I
thought it meant that you cannot insert any of the above
elements with innerHTML. Too bad the text is not more precise.
What does "for all objects ..." mean?

I haven't done much testing, but I fell into the innerHTML trap
once. If I remember correctly, I had tried to insert a table row
or an entire table inside an outer table, and Internet Explorer
failed with some error. At the time I had still believed that
one can insert anything with innerHTML.

But testing is not a good way to determine what works and what
will work in the future.

Perhaps it would be nice to have some JavaScript code that
shields us from such strange limitations and allows us to insert
anything with innerHTML. I think the jQuery .html(...) method
does that. I wouldn't be surprised if some people would count
this as an argument to use jQuery.

Hans-Georg