jQuery -- .html() vs. .text() vs. innerHTML vs. innerText/textContent (v11)

Revision 11 of this benchmark created on


Preparation HTML

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

<div id="test-element"></div>

Setup

var plainText = "testing";

Teardown



            $('#test-element').empty();
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery .html()
$('#test-element').html(plainText);
ready
jQuery .text()
$('#test-element').text(plainText);
ready
innerHTML
ready
innerText / textContent
ready
document.createTextNode
ready
document.createTextNode (cached)
ready

Revisions

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