Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undeprecate document.all #1196

Closed
jfbrennan opened this issue May 11, 2023 · 2 comments
Closed

Undeprecate document.all #1196

jfbrennan opened this issue May 11, 2023 · 2 comments

Comments

@jfbrennan
Copy link

jfbrennan commented May 11, 2023

I recently discovered document.all in an effort to find more direct ways of referencing elements with an id attribute, like window.myElementId apparently works.

Anyway, I was disappointed to read that document.all is deprecated (https://developer.mozilla.org/en-US/docs/Web/API/Document/all) despite being supported by all current versions of major browsers.

I'm not sure of any costs or legitimate issues with using document.all, but the DX is awesome:

<span id="welcomeMessage" hidden>Welcome!</span>

document.all.welcomeMessage.hidden = false;
document.getElementById('welcomeMessage').hidden = false;

What's the harm with un-deprecating this property? #221 appears to be more or less okay with it 🤷‍♂️

@bathos
Copy link

bathos commented May 11, 2023

The document.all attribute and the HTMLAllCollection interface are defined by the HTML spec, not the DOM spec. You will likely find more background and history there.

The getElementById method is safer (it will never return an HTMLCollection instead of an Element), more robust (consider the collisions that occur for ID values such as “__proto__”, “hasOwnProperty”, “length”, or even — given its own indexed access logic — “0”), and far less complicated.

@jfbrennan
Copy link
Author

Ah I see. If you did unfortunately have multiple elements with the same id then you get HTMLCollection not Element. Seems quite easy for a reasonable developer to avoid that as well as avoid accessing those other fields.

I'll move this to the HTML repo, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants