# add-html

> Adds html here and there in different spots around DOM nodes

Latest version **0.30.0** (published 2019-02-24) · 0 weekly downloads

## Install

```sh
npm install add-html
pnpm add add-html
yarn add add-html
bun add add-html
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.30.0 |
| Published | 2019-02-24 |
| First published | 2016-04-28 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | erikpukinskis |

## Links

- npm: https://www.npmjs.com/package/add-html
- Repository: https://github.com/erikpukinskis/add-html
- Homepage: https://github.com/erikpukinskis/add-html#readme
- Issues: https://github.com/erikpukinskis/add-html/issues
- npm.io page: https://npm.io/package/add-html

## Dependencies (1)

- [module-library](https://npm.io/package/module-library.md) *

## Recent versions

- 0.30.0 (latest) — 2019-02-24
- 0.29.0 — 2019-02-24
- 0.28.0 — 2018-10-24
- 0.27.0 — 2018-10-24
- 0.26.0 — 2018-10-18
- 0.25.0 — 2018-01-22
- 0.24.0 — 2018-01-20
- 0.23.0 — 2018-01-20
- 0.22.0 — 2018-01-20
- 0.21.0 — 2018-01-19
- 0.20.0 — 2017-07-25
- 0.19.0 — 2017-07-17
- 0.18.0 — 2017-07-17
- 0.17.0 — 2017-04-09
- 0.16.0 — 2017-04-04
- … 15 more at https://npm.io/package/add-html/versions

## README

A small helper library that takes care of turning HTML into DOM nodes, finding parents and siblings, and inserting new nodes relative to them:

```javascript
var third = document.querySelector("li:nth-of-type(3)")

var newHtml = "<div>A wild div appeared</div>"

addHtml.before(third, newHtml)
addHtml.after(third, newHtml)
addHtml.inside(third, newHtml)
addHtml.inPlaceOf(third, newHtml)
```

Or just add it to the bottom of the DOM:

```javascript
addHtml(newHtml)
```

If you want to do something with the nodes that were added, they are returned:

```javascript
var items = addHtml("<li>one</li><li>two</li><li>three</li>")
items[0].classList.add("selected")
```
### Designate a default place for things to get added

If you would like to have modules that add html to a centralized location on the page, without having to coordinate that location with each module, you can set a default container to add to:

```javascript
addHtml.defaultIn(".content")
addHtml("<b>Hiya</b>")
```

This will add **Hiya** to the `.content` div, as will any subsequent addHtml calls with no specific container or relative element.

You can also just set the default temporarily by passing a handler function:

```javascript
addHtml.defaultIn(".content")
// ...
addHtml.defaultIn(".sidebar-notes", function() {
  addStuffHere()
  moreStuff() // these modules can all use addHtml 
              // with no parameters, and any code
              // they add will go into the sidebar
})
addHtml("process complete") // this goes in .content
```

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