append-child

Append an HTML element to the DOM and return a removal function

Usage no npm install needed!

<script type="module">
  import appendChild from 'https://cdn.skypack.dev/append-child';
</script>

README

append-child Build Status

Append an HTML element to the DOM and return a removal function

Install

$ npm install --save append-child

Usage

var appendChild = require('append-child')
var element = document.createElement('div')

var remove = appendChild(element)
//=> div appended to body

remove()
//=> div removed from body

API

appendChild(element, [parent]) -> function

Returns a remove function.

element

Required
Type: HTMLElement

A DOM element to insert.

parent

Type: HTMLElement
Default: document.body

The parent element to append to.

License

MIT © Ben Drucker