In HTML, when parsing a table
element with tr
elements inside, a tbody
is usually inserted:
function log(el, ctx) {
var li = document.createElement('li');
li.appendChild(document.createTextNode(el.tagName.toLowerCase()));
var ul = document.createElement('ul');
for(var i=0; i<el.children.length; ++i)
log(el.children[i], ul);
li.appendChild(ul);
ctx.appendChild(li);
}
log(document.querySelector('table'), document.getElementById('dom-tree'));
table {
display: none;
}
<table>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
</table>
The table is parsed as:
<ul id="dom-tree"></ul>
Is this behavior standard?
I couldn't find it described in the spec, but it makes sense, because the insertRow
DOM method automatically creates tbody
elements too:
tr = table .
insertRow
( [ index ] )Creates a
tr
element, along with atbody
if required, inserts them into the table at the position given by the argument, and returns thetr
.