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

Element#id returns undefined #757

Open
zetashift opened this issue Jan 22, 2023 · 2 comments
Open

Element#id returns undefined #757

zetashift opened this issue Jan 22, 2023 · 2 comments

Comments

@zetashift
Copy link
Contributor

Element#id can return undefined, which can throw at times. Neither the spec, nor TypeScript prescribe anything.

https://dom.spec.whatwg.org/#ref-for-dom-element-id%E2%91%A0

Is the current situation enough, or do we want to return a UndefOr[String]?

@zetashift
Copy link
Contributor Author

In trying to reproduce this, I made the following:

const myElement = document.createElement("div")
console.log(myElement.id) // returns an empty string, ""


// const myApp = document.querySelector("notMyApp");
// ^^ will return null before you can access it

Can check it out here: https://jsfiddle.net/e5h0zx6v/
So I believe in practical usecases returning undefined will almost never happen, and that's maybe why the spec doesn't really mention it?

@armanbilge
Copy link
Member

So I believe in practical usecases returning undefined will almost never happen

Yeah, I wonder if actually you discovered a browser bug.

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

No branches or pull requests

2 participants