Skip to content

litejs/dom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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