Test case details

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++) { boxAnchor.appendChild(document.createElement('B').insertBefore(document.createTextNode('asdf fewf')).parentNode); } var box=document.getElementById('box'); function refreshRange() { box.parentNode.replaceChild(boxAnchor.cloneNode(true),box); box=document.getElementById('box'); } var range = document.createRange(); refreshRange(); function sleep(mseconds) { var e = new Date().getTime() + (mseconds); while (new Date().getTime() <= e) {} } </script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
refreshRange();
refreshRange();

Test cases

Test #1

while (box.firstChild) box.removeChild(box.firstChild);

Test #2

var last; while ((last = box.lastChild)) box.removeChild(last);

Test #3

while(box.hasChildNodes()) box.removeChild(box.firstChild);

Test #4

range.selectNodeContents(box); range.deleteContents();

Test #5

var newBox = box.cloneNode(false); box.parentNode.replaceChild(newBox,box); box=newBox;

Test #6

var parent = box.parentNode; var next = box.nextSibling; parent.removeChild(box); while(box.hasChildNodes()) box.removeChild(box.firstChild); parent.insertBefore(box,next);

Test #7

box.innerHTML = '';

Test #8

$(box).contents().remove();

Test #9

var display = box.style.display; box.style.display = 'none'; while(box.hasChildNodes()) box.removeChild(box.firstChild); box.style.display = display;

Test #10

$(box).empty();

Test #11

var last = box.lastChild; if (!last) sleep(300); while ((last = box.lastChild)) box.removeChild(last);