remove-children
v1.0.6
Published
Remove children from DOM-node
Downloads
18
Readme
remove-children
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