jQuery text() vs. html() (v47)

Revision 47 of this benchmark created by Broote on


Description

Compare performance of jQuery .text() and .html() methods when setting values. These values include not only plain text, but HTML to be rendered with using .html()

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<p id="text">Test text</p>
<script>
  var $text = $("#text");
</script>

Setup

$("#text").html('Initialized State, differs from the text/html being applied to this container.');

Test runner

Ready to run.

Testing in
TestOps/sec
text() with plain text
$text.text('Totally adding some text and stuff without any HTML tags.');
ready
html() with plain text
$text.html('Totally adding some text and stuff without any HTML tags.');
ready
html() with HTML
$text.html('<span>Actual HTML tags to be <i>rendered</i> with the addition</span>');
ready

Revisions

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