VK said:
The language was not perfect, but it is correct. In IE you must append a
row created with createElement to a tbody (or thead or tfoot) element. In
other browsers, you can add it to the table - where it will be appended as
the last child of the first tbody element.
IE automatically creates at least one tbody element during the initial
page parsing. So either you added <tbody> tag or not you still have
tBody section and appendChild will add rows to there.
Which is the correct behaviour for any standards compliant browser. A
tbody element is mandatory, the tags aren't.
At the same time <thead> and <tfoot> elements are not created
automatically, so in order to insert rows to tHead or tFoot you have to
mark up your table in advance (or create header and footer
pragrammatically)
Of course. thead and tfoot elements only exist if you put them in the
markup or create them using script. Otherwise they won't exist.
Other browsers do not create tBody automatically.
Which ones? If they don't, they aren't compliant with HTML 4.
On attempt to insert
a row to a table without <tbody> section three outcomes are possible:
1) the operation will fail
If the browser supports insertRow (which was part of DOM 1 in 1998), then
it should not fail. If it's not supported, feature testing should detect
that and some other solution should be attempted.
2) new row is added as direct child of table
In which browser? Any I've tested *always* create a tbody even if the tags
aren't coded in the HTML source, as per the HTML 4 specification.
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.
That IE has the same behaviour as other browsers doesn't mean they are
emulating IE, it just means IE follows the spec.
head and body tags are optional but the elements aren't, is that an
emulation of IE too?
While the 3rd one is currently the winning one, but all three outcomes
are still possible between different *rather modern* browsers and
versions.
Please state any modern browser that does either 1 or 2.
This is why I'd like to repeat: if one plans to script a table, always
markup <thead>, <tfoot> and <tbody> manyally, do not trust the parser.
That is not good advice. thead and tfoot are only required if you actually
use them, they aren't allowed to be empty so if you don't have any need for
them, don't code them. tbody *tags* are not mandatory, read the spec.
If you do not plan to script the table (add/remove/sort rows) then
<thead>, <tfoot> and <tbody> can be securely omited.
They can be securely omitted anyway.