jQuery: $(this) in each (v2)

Revision 2 of this benchmark created by Vlad Kras on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<ul>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ul>

Test runner

Ready to run.

Testing in
TestOps/sec
Using $(this)
$('li').each(function() {
  $(this).text('hello');
  $(this).css('color', 'blue');
});
ready
Using $this variable
$('li').each(function() {
  var $this = $(this);
  $this.text('hello');
  $this.css('color', 'blue');
});
ready

Revisions

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

  • Revision 1: published by Daniel Apt on
  • Revision 2: published by Vlad Kras on