dom-lite v23.2.1
DOM lite –
A small DOM implementation for testing, server-side rendering and working with html files.
Examples
const { document, DOMParser, XMLSerializer } = require("dom-lite");
const { XMLHttpRequest } = require("dom-lite/xmlhttprequest");
// 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();
const text1 = document.createTextNode("hello");
const text2 = document.createTextNode(" world");
fragment.appendChild(text1);
fragment.appendChild(text2);
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
External links
GitHub repo |
npm package |
DOM spec |
Selectors Level 3 |
Coveralls coverage
Buy Me A Tea
Licence
Copyright (c) 2014-2023 Lauri Rooden <lauri@rooden.ee>
The MIT License
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
4 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago