This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
This test case fails in all browsers that support document.all today (used to work in IE7, but IE8 changed behavior to be interoperable. The spec should be updated to match today's reality :-) I think the current behavior is that of the generic HTMLCollection.namedItem. <!DOCTYPE HTML> <html> <head> <title>collection.namedItem(name or id) returns collection of items with name or id</title> <link rel="help" href="http://www.w3.org/html/wg/drafts/html/master/infrastructure.html#htmlallcollection" /> <script type="text/javascript"> window.onload = function () { try { if (2 == document.all.namedItem("myelem").length) { document.getElementById("testresult").innerHTML = "Pass"; } } catch (ex) { document.getElementById("testresult").innerHTML = "Fail"; } } </script> </head> <body> <p>Description: Verify the collection of items with given name is returned (namedItem)</p> <p>Test passes if the word "Pass" appears below.</p> <a style="visibility: hidden" name="myelem"></a> <a style="visibility: hidden" id="myelem"></a> <div id="testresult">Fail</div> </body> </html>
(Note that since this is filed on the HTMLWG, it's not on my pile.) It's definitely not HTMLCollection.namedItem()'s behaviour (try changing the name='' attribute to id=''). And at least some browsers match the spec (Firefox, for one). Seems better to maintain compatibility with IE6, which was the main browser targeted by code that uses document.all, than to change this again.
assigning to Travis, since it's your bug.
Behaviors: 1. given an index, zero or one element may be returned 2. given a name, zero or first matching name/id element may be returned 3. given a name, zero, one, or a collection of matching name/id elements may be returned (I dusted off an IE6 for this--very nostalgic...) Test Results: API Spec IE6 IE8-IE10 Firefox Chrome --------------------------- ---- --- -------- ------- ------ HTMLCollection.item 1 1&3 1&3 1 1 HTMLCollection.namedItem 2 3 2 2 2* HTMLAllCollection.item 1&3 1&3 1&3 n/a 1&3 HTMLAllCollection.namedItem 1&3 3 2 n/a 3 *Returns the _last_ matching item for some reason These are interesting results to say the least. There may be something to say for splitting the behavior of HTMLAllCollection.namedItem from HTMLAllCollection.item, as that seems to be what browsers are doing. However, having what the spec defines is probably *over compatible* which isn't necessarily a bad thing. Given these results, I don't see a clear motivation to change the spec at this time. Implementations may still need time to solidify on the right behavior here, and the spec's current stance seems fine to me. At this point, I'm removing the CR keyword, as this should definitely not block the CR spec at this time.
Making this a higher priority to actively seek more feedback on from implementers and webdevs.
HTML5.1 Bugzilla Bug Triage: Moved to Github issue: https://github.com/w3c/html/issues/120 To file additional issues please use the W3C HTML5 Issue tracker: https://github.com/w3c/html/issues/new Thanks!