1.16 KB, text/html
From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4+) Gecko/20010927 BuildID: 2001092708 All getAttribute methods on the HTMLTableRowElement return nothing. However, directly addressing the attribute such as HTMLTableRowElement.sectionRowIndex returns the correct value. For example: var tr = document.getElementById("tr2"); tr.getAttribute("sectionRowIndex") returns nothing but calling tr.sectionRowIndex returns the correct value. Both methods above work correctly in IE (5.5 and 6.0). I've attached a test case that demonstrates this. Also reproducible with 0.94 on NT. Reproducible: Always Steps to Reproduce: See test case.
Ok here's my explanation... SectionRowIndex is not an attribute of the <tr> HTML tag. However it is a property of the HTMLTableRowElement DOM object. getAttribute returns the value of the attribute of the element. But since our tr object doesn't have such an attribute, it returns an empty string. However tr.sectionRowIndex works as expected. Did I miss something?
Fabian is correct, tr.foo != tr.getAttribute("foo") as per the DOM spec. IE is broken wrt this. INVALID>
Status: UNCONFIRMED → RESOLVED
Last Resolved: 17 years ago
Resolution: --- → INVALID
Thanks for the clarification. I understand the point that sectionRowIndex does not have an equivalent in the HTML 4.01 spec, and as such is not an attribute of the <tr> tag per se. However, is not a <tr> tag an implementation of the HTMLTableRowElement interface? As such, it should be able to return a value for the sectionRowIndex attribute. It does, of course, but only via tr.sectionRowIndex. Is not exposing properties in this way deprecated (section 2.5.1 of the DOM 1 HTML spec) and we are not all encouraged to use getAttribute instead? Does it not make it more difficult to use generic methods such as getAttribute, if there are many exceptions to this rule? Thanks for your insight.
All properties don't have equivalent HTML attributes, some properties are exposed only as properties of JS objects.
Peter, I'll try to explain quickly why this is invalid: There is a difference between an attribute defined by the mark-up language, and an attribute defined by the Document Object Model. They have the same name, but often we call DOM attributes "properties". I think you are confusing the two kind of attributes, because the W3C happened to define DOM attributes for most of the mark-up attributes. For example the "align" attribute of a div can be retrieved using div.getAttribute("align"), but the DOM also defines an "align" property on the HTMLDivElement interface. DOM attributes can _only_ be retrieved or set using Interface.attribute, and mark-up attributes can _only_ be retrieved or set using Element.get/setAttribute(). Feel free to email me any more questions :-) VERIFIED invalid.
Status: RESOLVED → VERIFIED
Component: DOM: HTML → DOM: Core & HTML
QA Contact: stummala → general
You need to log in before you can comment on or make changes to this bug.