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
- Host: GitHub
- URL: https://github.com/bendrucker/append-child
- Owner: bendrucker
- License: mit
- Created: 2016-07-04T15:33:49.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-08-19T23:36:39.000Z (almost 7 years ago)
- Last Synced: 2024-11-19T05:01:37.099Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# append-child [](https://travis-ci.org/bendrucker/append-child) [](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)