# @ultraq/dom-utils

> A collection of utilities for working with the DOM

Latest version **0.5.1** (published 2024-07-20) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @ultraq/dom-utils
pnpm add @ultraq/dom-utils
yarn add @ultraq/dom-utils
bun add @ultraq/dom-utils
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.1 |
| Published | 2024-07-20 |
| First published | 2019-04-27 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 38.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Emanuel Rabina |
| Maintainers | ultraq |
| Keywords | dom, utilities, event, delegate, deserialize, serialize |

## Links

- npm: https://www.npmjs.com/package/@ultraq/dom-utils
- Repository: https://github.com/ultraq/dom-utils
- Homepage: https://github.com/ultraq/dom-utils#readme
- Issues: https://github.com/ultraq/dom-utils/issues
- npm.io page: https://npm.io/package/@ultraq/dom-utils

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.5.1 (latest) — 2024-07-20
- 0.5.0 — 2023-09-22
- 0.4.0 — 2020-08-09
- 0.3.2 — 2020-06-14
- 0.3.1 — 2020-06-01
- 0.3.0 — 2020-06-01
- 0.2.0 — 2020-04-08
- 0.1.1 — 2019-04-27
- 0.1.0 — 2019-04-27

## README

dom-utils
=========

[![Build Status](https://github.com/ultraq/dom-utils/actions/workflows/build.yml/badge.svg)](https://github.com/ultraq/dom-utils/actions)
[![codecov](https://codecov.io/gh/ultraq/dom-utils/graph/badge.svg?token=1VI9MVLPJD)](https://codecov.io/gh/ultraq/dom-utils)
[![npm](https://img.shields.io/npm/v/@ultraq/dom-utils.svg?maxAge=3600)](https://www.npmjs.com/package/@ultraq/dom-utils)
[![Bundlephobia minified size](https://img.shields.io/bundlephobia/min/@ultraq/dom-utils)](https://bundlephobia.com/result?p=@ultraq/dom-utils)

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**

---
_Source: https://npm.io/package/@ultraq/dom-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
