Bug 83439 - HTMLCollection.namedItem returns a collection when there are multiple elements sharing the name
Summary: HTMLCollection.namedItem returns a collection when there are multiple element...
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-08 16:11 PDT by Boris Zbarsky
Modified: 2022-08-01 14:22 PDT (History)
8 users (show)

See Also:


Attachments
Testcase (293 bytes, text/html)
2012-04-08 16:11 PDT, Boris Zbarsky
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Boris Zbarsky 2012-04-08 16:11:06 PDT
Created attachment 136159 [details]
Testcase

Load the attached testcase.  It should say PASS, and does in non-WebKit browsers.  In WebKit it says FAIL.
Comment 1 Alexey Proskuryakov 2012-04-09 10:50:53 PDT
The difference with Firefox is that our result is a NodeList, not an HTMLImageElement. Re-titling the bug accordingly.

The attached test case tests this in a very roundabout way, so we need to test what IE actually does - even if the test passes there, it might be for another reason.

I'm not sure why we have this behavior, it seems like it was intentional at some point.
Comment 2 Boris Zbarsky 2012-04-09 11:01:12 PDT
I will bet you money you have this behavior because document.all needs it and as far as I can tell WebKit made document.all a vanilla HTMLCollection and propagated all its insanity to all HTMLCollections....
Comment 3 Pablo Flouret 2012-04-09 11:28:44 PDT
The implementations for namedItem are separate for document.all and other collections (in the bindings, which are custom), but they do the same thing.

By looking at the history, it seems HTMLCollection.namedItem has always returned a list when there's more than one element with the same name (and maybe always at first). Doesn't seem to be due to wanting to align with document.all.
Comment 4 Ahmad Saleem 2022-08-01 14:18:53 PDT
I am unable to reproduce this bug in Safari 15.6 on macOS 12.5 using attached test case and it is showing "PASS" and it is matching with other browsers (Chrome Canary 106 and Firefox Nightly 105). I think it was fixed along the way and can be marked as "RESOLVED CONFIGURATION CHANGED". Thanks!