@ultraq/dom-utils
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

dom-utils

Build Status codecov npm Bundlephobia minified size

A collection of utilities for working with the DOM.

Installation

npm install @ultraq/dom-utils

API

addEventDelegate(element, eventName, selector, handler)

Add an event listener to element that only fires when the target of the event matches selector.

  • element:
  • eventName:
  • selector:
  • handler:

clearChildren(element)

Removes all of an element's child nodes.

  • element

deserialize(htmlString)

Deserialize an HTML string into a document fragment.

  • htmlString

parseJsonFromElement(selector)

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(documentOrFragment)

Serialize a document or document fragment into an HTML string.

  • documentOrFragment

Dependencies (0)

    Dev Dependencies (12)

    Package Sidebar

    Install

    npm i @ultraq/dom-utils

    Weekly Downloads

    307

    Version

    0.5.0

    License

    Apache-2.0

    Unpacked Size

    38.7 kB

    Total Files

    12

    Last publish

    Collaborators

    • ultraq