Skip to content

Element#id returns undefined #757

@zetashift

Description

@zetashift
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]?

Activity

zetashift

zetashift commented on Jan 22, 2023

@zetashift
ContributorAuthor

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

armanbilge commented on Jan 22, 2023

@armanbilge
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zetashift@armanbilge

        Issue actions

          `Element#id` returns undefined · Issue #757 · scala-js/scala-js-dom