Skip to content

HTMLTableElement insertRow() has inaccurate description of default behavior #44987

Description

@speckins

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/insertRow

What specific section or headline is this issue about?

Intro, second paragraph

What information was incorrect, unhelpful, or incomplete?

If a table has multiple <tbody> elements, by default, the new row is inserted into the last <tbody>.

What did you expect to see?

According to the spec, that is only true if table.rows is empty. Otherwise, the table section into which the <tr> is inserted depends on the index. insertRow(i) inserts the new row into the parent of the table.rows[i] element. If the index is -1 or equal to the number of rows in table.rows, it is inserted into the parent of the last row.

I dug into this while debugging some JavaScript that was using table.insertRow(-1) to populate the body of a pre-existing HTML table which had a <thead> with one row and an empty <tbody>. According to the MDN docs, it should have appended the row to the <tbody>, but it was in fact appending it to the <thead>. But on reading the spec, it seems like Firefox is doing the right thing.

Do you have any supporting links, references, or citations?

https://html.spec.whatwg.org/multipage/tables.html#dom-table-insertrow

Do you have anything more you want to share?

No response

MDN metadata

Page report details

Metadata

Metadata

Assignees

No one assigned

    Labels

    Content:WebAPIWeb API docseffort: smallThis task is a small effort.good first issueA good issue for newcomers to get started with.

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions