unwrap vs replacewith (v5)

Revision 5 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="bob"></div>
<script>
  var bob = document.getElementById("bob");
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
unwrap
bob.innerHTML = "A nice house was found in <b>Toronto</b>.";
$('b', bob).contents().unwrap();
ready
replace with contents
bob.innerHTML = "A nice house was found in <b>Toronto</b>.";
$("b", bob).replaceWith(function() {
 return $(this).contents();
});
ready
replace with innerHTML
bob.innerHTML = "A nice house was found in <b>Toronto</b>.";
$("b", bob).replaceWith(function() {
 return this.innerHTML;
});
ready
native code
bob.innerHTML = "A nice house was found in <b>Toronto</b>.";
var b = document.getElementsByTagName('b');

while(b.length) {
    var parent = b[ 0 ].parentNode;
    while( b[ 0 ].firstChild ) {
        parent.insertBefore(  b[ 0 ].firstChild, b[ 0 ] );
    }
     parent.removeChild( b[ 0 ] );
}
ready

Revisions

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