jQuery attr vs Vanilla JS

JavaScript performance comparison

Test case created

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<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>

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');
Get id attribute using Vanilla JS
$('li').each(function(index, element) {
var itemId = element.id;

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment