1.0.6 • Published 7 years ago

remove-children v1.0.6

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

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

1.0.6

7 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago