remove-children

1.0.6 • Public • Published

remove-children

Build Status

Remove children from DOM-node

Motivation (stackoverflow)

It is tempting set innerHTML to empty-string, but it is slow.

var myNode = document.getElementById("foo");
myNode.innerHTML = '';

Somewhat unintuitively a while loop is much faster.

var myNode = document.getElementById("foo");
while (myNode.firstChild) {
    myNode.removeChild(myNode.firstChild);
}

Install

$ npm install --save remove-children

Usage

var removeChildren = require('remove-children')

var div = document.createElement('div')
div.appendChild(document.createElement('div'))
div.appendChild(document.createTextNode('some text'))

div.innerHTML
//=> '<div></div>some text'

removeChildren(div)

div.innerHTML
//=> ''

License

MIT © Sigurd Fosseng

Dependents (0)

Package Sidebar

Install

npm i remove-children

Weekly Downloads

0

Version

1.0.6

License

MIT

Last publish

Collaborators

  • laat