# on-load

> On load/unload events for DOM elements using a MutationObserver

Latest version **5.0.0** (published 2023-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install on-load
pnpm add on-load
yarn add on-load
bun add on-load
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2023-04-03 |
| First published | 2016-03-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 114 |
| Author | Kyle Robinson Young |
| Maintainers | mafintosh, yoshuawuyts, shama, bret, toddself, lrlna, emilbayes |
| Keywords | html, dom, element, onload, unload, yo-yo |

## Links

- npm: https://www.npmjs.com/package/on-load
- Repository: https://github.com/shama/on-load
- Issues: https://github.com/shama/on-load/issues
- npm.io page: https://npm.io/package/on-load

## Dependencies (2)

- [global](https://npm.io/package/global.md) ^4.4.0
- [nanoassert](https://npm.io/package/nanoassert.md) ^2.0.0

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 5.0.0 (latest) — 2023-04-03
- 4.0.2 — 2019-03-29
- 4.0.1 — 2018-08-10
- 4.0.0 — 2018-08-10
- 3.4.1 — 2018-06-28
- 3.4.0 — 2018-02-22
- 3.3.4 — 2017-12-03
- 3.3.3 — 2017-12-03
- 3.3.1 — 2017-09-18
- 3.3.0 — 2017-09-18
- 3.2.3 — 2017-09-11
- 3.2.2 — 2017-09-11
- 3.2.1 — 2017-09-05
- 3.2.0 — 2016-07-06
- 3.1.1 — 2016-07-06
- … 7 more at https://npm.io/package/on-load/versions

## README

# on-load

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Downloads][downloads-image]][downloads-url]
[![js-standard-style][standard-image]][standard-url]

On load/unload events for DOM elements using a MutationObserver

## usage

```js
const onload = require('on-load')

const div = document.createElement('div')
onload(div, function (el) {
  console.log('in the dom')
}, function (el) {
  console.log('out of the dom')
})

// Will fire the onload
document.body.appendChild(div)

// ... some time later

// Will fire the onunload
document.body.removeChild(div)
```

## API

### `onload(node, onloadFn, onunloadFn, [caller])`

Pass a dom `node` to `onload` to have a `onloadFn` function fire when the dom `node` is added to the document `dom` and a `onunloadFn` fire when the dom `node` is removed from the document `dom`.  Optionally a `caller` ID can be set to associate the onload/onunload hooks with a particular instance of of a dom `node`.  This is commonly used when 'componentizing' dom nodes.

# license
(c) 2023 Kyle Robinson Young. MIT License

[npm-image]: https://img.shields.io/npm/v/on-load.svg?style=flat-square
[npm-url]: https://npmjs.org/package/on-load
[travis-image]: https://img.shields.io/travis/shama/on-load/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/shama/on-load
[downloads-image]: http://img.shields.io/npm/dm/on-load.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/on-load
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[standard-url]: https://github.com/feross/standard

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