jQuery text() vs. html() vs [0] vs native (v33)

Revision 33 of this benchmark created by Heavensrevenge on


Preparation HTML

<script src="//code.jquery.com/jquery-git2.min.js"></script>

<p id="text">Test text</p>
<input id="title" type="text" placeholder="Main Title">

Setup

var $text = $("#text");
    var $title= $("#title");

Test runner

Ready to run.

Testing in
TestOps/sec
text()
$text.text();
ready
html()
$text.html();
ready
innerText
$text[0].innerText;
ready
innerHTML
$text[0].innerHTML;
ready
text().contains
$text.text().contains("Test text");
ready
html().contains
$text.html().contains("Test text");
ready
innerText.contains
$text[0].innerText.contains("Test text");
ready
.text() set
$text.text("New Text");
ready
.html() set
$text.html("New Text");
ready
.prop set
$title.prop("value", "COMPLETELY New Title");
ready
.prop get
$title.prop("value");
ready
.val() set
$title.val("COMPLETELY New Title");
ready
.val() get
$title.val();
ready
.innerText set
$text[0].innerText = "New Text";
ready

Revisions

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