23.12.1 • Published 5 months ago

@litejs/dom v23.12.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

LiteJS DOM Coverage Size Buy Me A Tea

A small DOM library for server-side testing, rendering, and handling of HTML files.
DOM spec | Selectors Level 3

Examples

const { document, DOMParser, XMLSerializer } = require("@litejs/dom");
const { XMLHttpRequest } = require("@litejs/dom/net.js");

// Use XMLHttpRequest in server side
var xhr = new XMLHttpRequest()
xhr.open("GET", "https://litejs.com")
xhr.responseType = "document"
xhr.onload = function() {
	var doc = xhr.responseXML
	// Work with DOM in familiar way
	console.log(doc.querySelector("title").textContent)
}
xhr.send()

// Build DOM manually
const el = document.createElement("h1");
el.id = 123;
el.className = "large";

const fragment = document.createDocumentFragment();
fragment.appendChild(document.createTextNode("hello"));
fragment.appendChild(document.createTextNode(" world"));
el.appendChild(fragment);

el.innerHTML;
// hello world
el.innerHTML = "<b>hello world</b>";
el.toString();
// <h1 id="123" class="large"><b>hello world</b></h1>

// minify output
el.toString(true);
// <h1 id=123 class=large><b>hello world</b></h1>

el.querySelectorAll("b");
// [ "<b>hello world</b>" ]

Contributing

Follow Coding Style Guide, run tests npm install; npm test.

Copyright (c) 2014-2023 Lauri Rooden <lauri@rooden.ee>
MIT License | GitHub repo | npm package | Buy Me A Tea

23.12.1

5 months ago

23.12.0

5 months ago

23.11.1

6 months ago

23.8.0

9 months ago

23.7.0

10 months ago

23.11.0

6 months ago

23.4.0

1 year ago

23.3.0

1 year ago

23.2.2

1 year ago