This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 22328 - HTMLAllCollection.namedItem doesn't match reality
Summary: HTMLAllCollection.namedItem doesn't match reality
Status: RESOLVED MOVED
Alias: None
Product: HTML WG
Classification: Unclassified
Component: HTML5 spec (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P1 normal
Target Milestone: ---
Assignee: Travis Leithead [MSFT]
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard: whatwg-resolved
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-11 17:50 UTC by Travis Leithead [MSFT]
Modified: 2016-10-25 08:59 UTC (History)
7 users (show)

See Also:


Attachments

Description Travis Leithead [MSFT] 2013-06-11 17:50:39 UTC
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>
Comment 1 Ian 'Hixie' Hickson 2013-07-03 18:23:28 UTC
(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.
Comment 2 Silvia Pfeiffer 2013-07-13 10:33:31 UTC
assigning to Travis, since it's your bug.
Comment 3 Travis Leithead [MSFT] 2013-07-20 00:32:39 UTC
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.
Comment 4 Michael[tm] Smith 2015-06-16 10:19:01 UTC
Making this a higher priority to actively seek more feedback on from implementers and webdevs.
Comment 5 Travis Leithead [MSFT] 2016-04-25 22:39:57 UTC
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!