Closed Bug 295561 Opened 20 years ago Closed 20 years ago

[FIXr]DOM tables: can't access rows collections by ID

Categories

(Core :: DOM: Core & HTML, defect, P1)

defect

Tracking

()

VERIFIED FIXED
mozilla1.8beta4

People

(Reporter: brett.donald, Assigned: bzbarsky)

References

()

Details

(Keywords: fixed1.8, testcase)

Attachments

(4 files, 1 obsolete file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 According to the DOM Level 2 spec I should be able to access the rows[] and cells[] collections using either the ordinal or the id/name. However, I only seem to be able to use an ordinal to access rows and cells. This works: table_element.rows[0].cells[0] This works in IE not FF: table_element.rows["row1"].cells["cell1"] This works in IE not FF: table_element.rows.namedItem("row1").cells.namedItem("cell1") Reproducible: Always Steps to Reproduce: Browse to the supplied URL Actual Results: No alert messages are displayed. JavaScript Console reports the following error: Error: document.getElementById("table1").rows.namedItem("table1row2") has no properties Source File: http://castlehillsda.org/test_table.html Line: 6 Expected Results: Two alert messages should fire when the page loads, displaying the contents of the central cell in the table. This works correctly in IE6.
Keywords: testcase
I think this is the spec you mean. rows: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-6156016 cells: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-67349879 interface HTMLCollection: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75708506 The .namedItem method is also defined in the HTMLCollection: This: alert(document.getElementById("table1").rows["table1row2"].cells["table1row2cell2"] is not correct. This: rows["table1row2"] is a neat way in js and means practically the same as rows.item("table1row2") and that is not correct because .item() method only accepts an integer, see the interface HTMLCollection link. This: alert(document.getElementById("table1").rows.namedItem("table1row2").cells.namedItem("table1row2cell2").innerHTML) seems correct though. I don't know why this one fails.
Attached file Testcase2
This works fine in Opera8 and IE6. And according to dom level2 html, this should work, I think. .namedItem() seems to work for form elements, though. See the testcase in bug 80627.
Status: UNCONFIRMED → NEW
Ever confirmed: true
The cells collection works fine; none of the testcases here actually test it (they all die at the row collections part). Martijn, in the DOM JS bindings HTMLCollection['string'] is mapped to HTMLCollection.namedItem('string'). Using a numeric property id maps to item() instead, as you pointed out.
Assignee: general → bzbarsky
OS: Windows XP → All
Priority: -- → P1
Hardware: PC → All
Summary: DOM tables: can't access rows and cells collections by ID → [FIX]DOM tables: can't access rows collections by ID
Target Milestone: --- → mozilla1.8beta4
Attached patch PatchSplinter Review
Attachment #190981 - Flags: superreview?(jst)
Attachment #190981 - Flags: review?(jst)
Comment on attachment 190981 [details] [diff] [review] Patch Nice :) r+sr=jst
Attachment #190981 - Flags: superreview?(jst)
Attachment #190981 - Flags: superreview+
Attachment #190981 - Flags: review?(jst)
Attachment #190981 - Flags: review+
Comment on attachment 190981 [details] [diff] [review] Patch Requesting 1.8b4 approval. This is pretty safe and improves compat with both spec and IE.
Attachment #190981 - Flags: approval1.8b4?
Summary: [FIX]DOM tables: can't access rows collections by ID → [FIXr]DOM tables: can't access rows collections by ID
Attachment #190981 - Flags: approval1.8b4? → approval1.8b4+
Fixed on trunk and 1.8 branch.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Keywords: fixed1.8
Verified on: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4) Gecko/20050817 Firefox/1.0+ Thanks zbarsky!
Status: RESOLVED → VERIFIED
the test case should be converted into a mochitest
Flags: in-testsuite?
Attached file MochiTest (obsolete) —
Attachment #317235 - Flags: review?(bernd_mozilla)
Attachment #317235 - Flags: review?(bernd_mozilla) → review+
Checkin needed, please. I believe the Mochitest should be placed in mozilla/dom/tests/mochitest/bugs/ and Makefile.in must be modified?
Whiteboard: [checkin needed]
Actually, it needs to go in content/html/content/test. And I'll expand on the test a bit before checking it in (test multiple tbodies, for example). Oh, and in general you want the "checkin-needed" keyword, not a status whiteboard annotation.
Thanks for the info. I was wondering about adding stuff to the testcase, too. For example what should happen if two or more rows have the same id (not allowed theoretically, but anyway)? First one wins, just like getElementById?
Attached patch Test as diffSplinter Review
Attachment #317235 - Attachment is obsolete: true
Checked in the test
Flags: in-testsuite? → in-testsuite+
Whiteboard: [checkin needed]
Yeah, if there are multiple things with the same id, first one wins. If you want to add more tests here, please do!
Component: DOM: HTML → DOM: Core & HTML
QA Contact: ian → general
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: