Ian Collins wrote:
RobG wrote:
3) on the first attempt to insert a row tBody section is created and
new row is added as a child if it (namely emulation of IE behavior).
Rubbish. The tbody is created when the HTML source for the table is
parsed, whether the tags are there or not because that is what the
HTML 4 spec says should happen. It is not created as a result of
using insertRow.
Not rubbish, it depends on the context. If you are building a table in
script, the tbody will be added when you add the first row, try:
The bit that is rubbish is the phrase 'emulation of IE behavior' - it is
conforming to the W3 DOM 2 specification.
<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-39872903>
Your point is valid, but the discussion wasn't about building a table
with script, it was about inserting a new row into an existing table and
in that context the tbody already exists.
It is also interesting to compare the behaviour of different browsers
when adding a row using the HTMLTableElemen t::insertRow method and the
Node::appendChi ld method.
insertRow is 'safer' as in conforming browsers it automatically handles
the tbody issue. When adding rows with appendChild, not all browsers
will handle adding the row to a table (e.g. IE), they require the row to
be explicitly added to a tbody (or other table section). appendChild
might be more widely supported and is a reasonable first fallback.
If you have a table with more than one section (say with a thead, tfoot
or multiple tbodys) then you should get a reference to the correct table
section anyway to add the row - otherwise insertRow will just add the
row to the last tbody element.
[...]
--
Rob