b-fuze / deno-dom

Browser DOM & HTML parser in Deno
https://jsr.io/@b-fuze/deno-dom
MIT License
425 stars 47 forks source link

set id appears to set the attribute name with the value of the id we want to set #83

Closed fabiancook closed 2 years ago

fabiancook commented 2 years ago

https://github.com/b-fuze/deno-dom/blob/af5626565c747c027a2fe8fb76bd3ac84673c738/src/dom/element.ts#L306

Instead of setAttribute("id", this.#currentId = id), the above code is used.

I checked this here:

const div: HTMLElement = <div />

console.log({ div, instance: div instanceof HTMLElement });

const expectedId = `${Math.random()}`

div.id = expectedId;

console.log({ id: div.getAttribute("id"), [expectedId]: div.getAttribute(expectedId) });

ok(div.getAttribute("id") === expectedId || div.getAttribute(expectedId) === expectedId);

We get the log

{
  div: EventTarget { .... },
  instance: true
}
{ id: null, "0.5037532964515365": "0.5037532964515365" }
fabiancook commented 2 years ago

Resolve with https://github.com/b-fuze/deno-dom/pull/84