A collection of utilities for working with the DOM.
npm install @ultraq/dom-utils
Add an event listener to element
that only fires when the target of the event
matches selector
.
- element:
- eventName:
- selector:
- handler:
Removes all of an element's child nodes.
- element
Deserialize an HTML string into a document fragment.
- htmlString
Parse the text content of the element picked out by the given selector as JSON
data, returning it as an object. Returns null
if no data could be read.
- selector: a CSS selector for picking out the HTML element that contains the JSON data
-
scope: optional, the DOM tree to run the selector over. Defaults to the
current
document
.
Serialize a document or document fragment into an HTML string.
- documentOrFragment