jQuery attr vs Vanilla JS

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<ul>
<li id="item1">Item 1 with id attribute</li>
<li id="item2">Item 2 with id attribute</li>
<li id="item3">Item 3 with id attribute</li>
</ul>

Preparation code output

  • Item 1 with id attribute
  • Item 2 with id attribute
  • Item 3 with id attribute

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Get id attribute using jQuery
$('li').each(function() {
var itemId = $(this).attr('id');
});
pending…
Get id attribute using Vanilla JS
$('li').each(function(index, element) {
var itemId = element.id;
});
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment