deno-dom: Element.removeAttribute() sets the attribute to null rather than to undefined

Or alternatively, the different Element APIs treat null and undefined in inconsistent ways.

import { DOMParser } from "https://raw.githubusercontent.com/b-fuze/deno-dom/master/deno-dom-wasm.ts";

const document = new DOMParser().parseFromString(
  "<html attribute=value>",
  "text/html"
);

const html = document!.documentElement!;
html.removeAttribute("attribute");

console.log(html.hasAttribute("attribute"));    // true
console.log(html.getAttribute("attribute"));    // null
console.log(html.attributes.attribute);         // null

console.log(html.hasAttribute("nonexistent"));  // false
console.log(html.getAttribute("nonexistent"));  // null
console.log(html.attributes.nonexistent);       // undefined

// <html attribute><head></head><body></body></html>
console.log(html.outerHTML);

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Awesome, thanks for the quick fix!

@0kku Agree. The goal of the project is to match the DOM spec as closely as possible, right?

Yes. I too share @b-fuze’s grievances, but our goal is to follow the spec despite its faults. That way DOM abstraction libs that make life easier can be used without compatibility issues, and people who just want to go vanilla don’t have to relearn anything.

While we can probably all agree that the DOM API is horrible in more ways than one and ideally we’d design a better API from the ground-up without the legacy baggage… This is probably not the best place to discuss that 😅