[thelist] innerHTML on a table (Was: AJAX Tip)

Mattias Thorslund mattias at thorslund.us
Thu Apr 6 23:57:32 CDT 2006


To clarify my earlier post a little:
What I tried and couldn't do in IE was to set innerHTML on a TR, in
order to update just one row.

What I wanted to do (in concept):

oTD.innerHTML = '<td class="myclass" id="someID">content</td><td
class="anotherclass">more content</td>';

Since the content for the row was generated by the server, this would
have been very handy, especially since I wanted to replace not only the
content of the TDs but also the class attributes. This worked fine in
Firefox, but not in IE.

Instead I had to do this (feel free to tell me what's wrong/bad about this):

//get the row object
oRow = document.getElementById('row'+rowID.toString());

//walk through the properties in the js object received via XHR/JSON
//and set the properties on the cells of the TD
for(cellID in newCells){
       oCell = oRow.cells[cellID];
       oCell.innerHTML = newCells[cellID].innerHTML;
       oCell.className = newCells[cellID].className;
}


Quoting from MSDN [1]:
> The property is read/write for all objects except the following, for
> which it is read-only: COL, COLGROUP, FRAMESET, HTML, STYLE, TABLE,
> TBODY, TFOOT, THEAD, TITLE, TR. The property has no default value.

So, according to that, it wouldn't be possible to set innerHTML of a
TBODY...


Cheers,

Mattias


[1]
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/innerhtml.asp




Pavel Dudrenov wrote:
> To enshure that IE displays the content of a table the table needs to have a
> tbody element. And put wahtever table elements you need to put in the tbody
> not the table directly.
>
> Pavel
> P.S.
> Avoid using innerHTML.
>
> On 4/6/06, Christian Heilmann <codepo8 at gmail.com> wrote:
>   
>>>> In case someone reading the above thought of doing some innerHTML in
>>>> tables:
>>>>         
>> It is even worse:
>>
>> DOM generated tables will not show.
>> http://icant.co.uk/sandbox/msieXHRtable/exampleXMLxhr.html
>>
>> This works nicely in Firefox but not in MSIE. MSIE gets and sets the
>> innerHTML, but the table is not shown. Is that some messed up
>> hasLayout thing?
>>
>> --
>> Chris Heilmann
>> Blog: http://www.wait-till-i.com
>> Writing: http://icant.co.uk/
>> Binaries: http://www.onlinetools.org/
>> --
>>
>> * * Please support the community that supports you.  * *
>> http://evolt.org/help_support_evolt/
>>
>> For unsubscribe and other options, including the Tip Harvester
>> and archives of thelist go to: http://lists.evolt.org
>> Workers of the Web, evolt !
>>
>>     




More information about the thelist mailing list