cellIndex is -1 for th without a tr parent (should be 0 per current HTML5 draft)

RESOLVED INVALID

Status

()

Core
DOM: Core & HTML
RESOLVED INVALID
6 years ago
5 years ago

People

(Reporter: Colin Williams, Unassigned)

Tracking

10 Branch
x86
Linux
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

6 years ago
Created attachment 615624 [details]
A test case for the bug.

I make a table through javascript and the DOM tree. I then try to get the cellIndex for a th from the table and I get -1 ...


Similar to bug https://bugzilla.mozilla.org/show_bug.cgi?id=255381 , however that bug claims cellIndex does work..

Updated

6 years ago
Attachment #615624 - Attachment mime type: text/plain → text/html
Current spec draft at http://www.whatwg.org/specs/web-apps/current-work/multipage/tabular-data.html#dom-tdth-cellindex says:

  The cellIndex IDL attribute must, if the element has a parent tr element, return the
  index of the cell's element in the parent element's cells collection. If there is no
  such parent element, then the attribute must return 0.

the <th> elements in this testcase are not inside a <tr>, so we should be returning 0.  Looks like this is a recent spec change; DOM level 1 and 2 did not define behavior for cells that are not in a row, so we returned -1 in that case.

That said, compat across browsers is poor here: WebKit returns all sorts of different indices, while Opera seems to not implement this property at all.  IE9 returns 0 like the current spec draft says, so I'm guessing hixie just went with the IE behavior for simplicity.  Ms2ger, do you think it's worth making the case that returning an obviously invalid value when the value is meaningless is better, or should we just switch to 0?
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: cellIndex is -1 for th from dynamic table → cellIndex is -1 for th without a tr parent (should be 0 per current HTML5 draft)
I filed https://www.w3.org/Bugs/Public/show_bug.cgi?id=16757
From code inspection, webkit returns the number of previous siblings that are th/td's.
Even if there is no parent table and other nodes in between so that the ths/tds end up in separate tables in the layout?
Spec changed.
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.