This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
The current dom spec says at: http://dom.spec.whatwg.org/#interface-htmlcollection """ The supported property names are the values from the list returned by these steps: 1. Let result be an empty list. 2. For each element represented by the collection, in tree order, run these substes: 1. If element is in the HTML namespace and has a name attribute whose value is neither the empty string nor is in result, append element's name attribute value to result. 2. If element has an ID which is neither the empty string nor is in result, append element's ID to result. 3. Return result. """ This means that when an element contributes both its id and name, the name will precede the id in result. This seems odd because this is the opposite behavior of HTMLCollection subclasses: http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#collections-0 The HTML5 spec for these collections always indicates: "with the id of an element preceding its name if it contributes both". Behavior of existing browsers: - Firefox 27 has the id preceding the name (see http://jsfiddle.net/59wrt/2/) - IE11 does not return the Element's id if the Element contributes its name :( - Chrome. This is not supported yet in stable releases but I have recently implemented this as per the spec (http://code.google.com/p/chromium/issues/detail?id=341269). For HTMLCollection, the name precedes the id. For HTMLCollection subclasses the id precedes the name. However, this has not shipped yet so there is still time to fix it if the spec gets updated.
Arguably, we should not enumerate the names/ids at all and just enumerate the indices. That's what Gecko used to do, and more closely matches what websites expect, which is for every element to be the value for one single key during the enumeration. Of course getOwnPropertyNames still needs to be defined.
I agree with bz that enumeration should ideally only give you back elements. Can anyone help out with IDL hooks for that? Christophe, do I understand it correctly that you would like step 2.1 and 2.2 swapped? Aligning this with HTML makes sense to me. I should have been more careful here.
(In reply to Anne from comment #2) > Christophe, do I understand it correctly that you would like step 2.1 and > 2.2 swapped? Aligning this with HTML makes sense to me. I should have been > more careful here. Yes, you understood correctly. This is would be great.
https://github.com/whatwg/dom/commit/8b9338049201d075b1cae365562dfb40fe46d567 Leaving open for the comment bz made.
We have IDL hooks for this. Or rather prose hooks. See <http://heycam.github.io/webidl/#property-enumeration>, but basically you can just say that some subset (or all) of the named properties are "unenumerable" to have them not show up during enumeration.
Made them unenumerable. https://github.com/whatwg/dom/commit/c812a0aafaa92460ffdd333418e03f2790fa742a Browser bugs for future reference: * https://bugzilla.mozilla.org/show_bug.cgi?id=843840 * https://bugs.webkit.org/show_bug.cgi?id=110612