javascript remove all child nodes javascript / jquery

JavaScript performance comparison

Revision 413 of this test case created by

Preparation code

<div id="box"></div>

<script>
var boxAnchor = document.createElement('div');
boxAnchor.style.cssText="white-space:nowrap";
boxAnchor.id = 'box';
for(var i=0;i<1000;i++)
{
var b = document.createElement('B');
boxAnchor.appendChild(b.insertBefore(document.createTextNode('asdf fewf'), b.firstChild).parentNode);
}
var box=document.getElementById('box');
function refreshRange()
{
box.parentNode.replaceChild(boxAnchor.cloneNode(true),box);
box=document.getElementById('box');
}
var range = document.createRange();
refreshRange();
</script>

<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
var jq111 = jQuery.noConflict(true);
</script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script>
var jq213 = jQuery.noConflict(true);
</script>
    

Preparation code output

<div id="box"></div>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
children forEach removeChild
refreshRange();
[].slice.call(box.children).forEach(function(child) {
  box.removeChild(child);
});
pending…

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments