jQuery text() vs. html() (v36)

Revision 36 of this benchmark created on


Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
text()
$text.text();
ready
html()
$text.html();
ready
add text()
$text.text('blah blah');
ready
add html()
$text.html('blah blah')
ready
add text() after check
var a= 'blah blah';
if($text.text() != a)
$text.text(a);
ready
each
var valueToDisplay= 'blah blah';
$.each($text, function(){
                            var dom = $(this);
                            if(dom.text() != valueToDisplay)
                            {
                                dom.text(valueToDisplay);
                            }
                        });
ready

Revisions

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