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)
Core
DOM: Core & HTML
Tracking
()
VERIFIED
FIXED
mozilla1.8beta4
People
(Reporter: brett.donald, Assigned: bzbarsky)
References
()
Details
(Keywords: fixed1.8, testcase)
Attachments
(4 files, 1 obsolete file)
802 bytes,
text/html
|
Details | |
580 bytes,
text/html
|
Details | |
8.49 KB,
patch
|
jst
:
review+
jst
:
superreview+
asa
:
approval1.8b4+
|
Details | Diff | Splinter Review |
4.23 KB,
patch
|
Details | Diff | Splinter Review |
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.
Comment 1•20 years ago
|
||
Comment 2•20 years ago
|
||
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.
Comment 3•20 years ago
|
||
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.
Updated•20 years ago
|
Status: UNCONFIRMED → NEW
Ever confirmed: true
![]() |
Assignee | |
Comment 4•20 years ago
|
||
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
![]() |
Assignee | |
Comment 5•20 years ago
|
||
Attachment #190981 -
Flags: superreview?(jst)
Attachment #190981 -
Flags: review?(jst)
Comment 6•20 years ago
|
||
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+
![]() |
Assignee | |
Comment 7•20 years ago
|
||
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?
![]() |
Assignee | |
Updated•20 years ago
|
Summary: [FIX]DOM tables: can't access rows collections by ID → [FIXr]DOM tables: can't access rows collections by ID
Updated•20 years ago
|
Attachment #190981 -
Flags: approval1.8b4? → approval1.8b4+
![]() |
Assignee | |
Comment 8•20 years ago
|
||
Fixed on trunk and 1.8 branch.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Reporter | ||
Comment 9•20 years ago
|
||
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
Comment 11•17 years ago
|
||
Attachment #317235 -
Flags: review?(bernd_mozilla)
Attachment #317235 -
Flags: review?(bernd_mozilla) → review+
Comment 12•17 years ago
|
||
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]
![]() |
Assignee | |
Comment 13•17 years ago
|
||
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.
Comment 14•17 years ago
|
||
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?
![]() |
Assignee | |
Comment 15•17 years ago
|
||
Attachment #317235 -
Attachment is obsolete: true
![]() |
Assignee | |
Comment 16•17 years ago
|
||
Checked in the test
Flags: in-testsuite? → in-testsuite+
Whiteboard: [checkin needed]
![]() |
Assignee | |
Comment 17•17 years ago
|
||
Yeah, if there are multiple things with the same id, first one wins.
If you want to add more tests here, please do!
You need to log in
before you can comment on or make changes to this bug.
Description
•