Substituting one tag for another with jQuery

JavaScript performance comparison

Test case created by Jens Roland

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<code>A</code><code>B</code><code>C</code><code>D</code><code>E</code>
<code>F</code><code>G</code><code>H</code><code>I</code><code>J</code>
<code>A</code><code>B</code><code>C</code><code>D</code><code>E</code>
<code>F</code><code>G</code><code>H</code><code>I</code><code>J</code>
<code>A</code><code>B</code><code>C</code><code>D</code><code>E</code>
<code>F</code><code>G</code><code>H</code><code>I</code><code>J</code>
<code>A</code><code>B</code><code>C</code><code>D</code><code>E</code>
<code>F</code><code>G</code><code>H</code><code>I</code><code>J</code>
<code>A</code><code>B</code><code>C</code><code>D</code><code>E</code>
<code>F</code><code>G</code><code>H</code><code>I</code><code>J</code>

<code>
<span>A</span><span>B</span><span>C</span><span>D</span><span>E</span>
<span>F</span><span>G</span><span>H</span><span>I</span><span>J</span>
</code>
<code>
<span>A</span><span>B</span><span>C</span><span>D</span><span>E</span>
<span>F</span><span>G</span><span>H</span><span>I</span><span>J</span>
</code>
<code>
<span>A</span><span>B</span><span>C</span><span>D</span><span>E</span>
<span>F</span><span>G</span><span>H</span><span>I</span><span>J</span>
</code>
<code>
<span>A</span><span>B</span><span>C</span><span>D</span><span>E</span>
<span>F</span><span>G</span><span>H</span><span>I</span><span>J</span>
</code>
<code>
<span>A</span><span>B</span><span>C</span><span>D</span><span>E</span>
<span>F</span><span>G</span><span>H</span><span>I</span><span>J</span>
</code>

    

Preparation code output

<code>A</code><code>B</code><code>C</code><code>D</code><code>E</code> <code>F</code><code>G</code><code>H</code><code>I</code><code>J</code> <code>A</code><code>B</code><code>C</code><code>D</code><code>E</code> <code>F</code><code>G</code><code>H</code><code>I</code><code>J</code> <code>A</code><code>B</code><code>C</code><code>D</code><code>E</code> <code>F</code><code>G</code><code>H</code><code>I</code><code>J</code> <code>A</code><code>B</code><code>C</code><code>D</code><code>E</code> <code>F</code><code>G</code><code>H</code><code>I</code><code>J</code> <code>A</code><code>B</code><code>C</code><code>D</code><code>E</code> <code>F</code><code>G</code><code>H</code><code>I</code><code>J</code> <code> <span>A</span><span>B</span><span>C</span><span>D</span><span>E</span> <span>F</span><span>G</span><span>H</span><span>I</span><span>J</span> </code> <code> <span>A</span><span>B</span><span>C</span><span>D</span><span>E</span> <span>F</span><span>G</span><span>H</span><span>I</span><span>J</span> </code> <code> <span>A</span><span>B</span><span>C</span><span>D</span><span>E</span> <span>F</span><span>G</span><span>H</span><span>I</span><span>J</span> </code> <code> <span>A</span><span>B</span><span>C</span><span>D</span><span>E</span> <span>F</span><span>G</span><span>H</span><span>I</span><span>J</span> </code> <code> <span>A</span><span>B</span><span>C</span><span>D</span><span>E</span> <span>F</span><span>G</span><span>H</span><span>I</span><span>J</span> </code>

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
wrap-unwrap
$('code').contents().unwrap().wrap('<div/>');
pending…
replaceWith string
$('code').each(function() {
  $(this).replaceWith( "<div>" + $(this).html() + "</div>" );
});
pending…
replaceWith function
$('code').replaceWith(function(){
  return $("<div />", {html: $(this).html()});
});
pending…

Compare results of other browsers

Revisions

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

0 Comments

ABCDE FGHIJ ABCDE FGHIJ ABCDE FGHIJ ABCDE FGHIJ ABCDE FGHIJ ABCDE FGHIJ ABCDE FGHIJ ABCDE FGHIJ ABCDE FGHIJ ABCDE FGHIJ