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
- fix: removeAttribute actually deletes attribute #30 — committed to b-fuze/deno-dom by b-fuze 3 years ago
Awesome, thanks for the quick fix!
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 😅