An open API service indexing awesome lists of open source software.

https://github.com/bendrucker/append-child

Append an HTML element to the DOM and return a removal function
https://github.com/bendrucker/append-child

Last synced: about 1 year ago
JSON representation

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

Awesome Lists containing this project

README

          

# append-child [![Build Status](https://travis-ci.org/bendrucker/append-child.svg?branch=master)](https://travis-ci.org/bendrucker/append-child) [![Greenkeeper badge](https://badges.greenkeeper.io/bendrucker/append-child.svg)](https://greenkeeper.io/)

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

## Install

```
$ npm install --save append-child
```

## Usage

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

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

remove()
//=> div removed from body

var parent = document.createElement('div')
remove = appendChild(element, parent)
//=> div appended to parent

remove()
//=> div removed from parent
```

## 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](http://bendrucker.me)