Skip to content

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

License

Notifications You must be signed in to change notification settings

bendrucker/append-child

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

append-child Build Status Greenkeeper badge

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 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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published