An implementation of the browser DOM—primarily for SSR—in Deno. Implemented with Rust, WASM, and obviously, Deno/TypeScript.
import { DOMParser, Element } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
const doc = new DOMParser().parseFromString(`
<h1>Hello World!</h1>
<p>Hello from <a href="https://deno.land/">Deno!</a></p>
`, "text/html")!;
const p = doc.querySelector("p")!;
console.log(p.textContent); // "Hello from Deno!"
console.log(p.childNodes[1].textContent); // "Deno!"
p.innerHTML = "DOM in <b>Deno</b> is pretty cool";
console.log(p.children[0].outerHTML); // "<b>Deno</b>"
Deno DOM has two backends, WASM and native using Deno native plugins. Both APIs are identical, the difference being only in performance. The WASM backend works with all Deno restrictions, but the native backend requires the --unstable --allow-plugin
flags. You can switch between them by importing either deno-dom-wasm.ts
or deno-dom-native.ts
.
Deno DOM is still under development, but is fairly usable for basic HTML manipulation needs.
<script>
tags, onload
, etc)<marquee>
, etc)Author: b-fuze
Source Code: https://github.com/b-fuze/deno-dom
#deno #nodejs #node #javascript