querySelectorAll vs getElementsByTagName

JavaScript performance comparison

Revision 90 of this test case created by karthick

Preparation code

<div>
  <ul>
    <li><a class='first listItem' href="#">item 1</a></li>
    <li><a href="#">item 2</a></li>
    <li><a href="#">item 3</a></li>
  </ul>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
querySelectorAll
var nodes = document.querySelectorAll('a')
pending…
getElementsByTagName
var nodes = document.getElementsByTagName('a')
pending…
jquery
var nodes = jQuery('a')
pending…
jquery
var nodes = $('a')
pending…
jQuery ClassName
var nodes = $('.first')
pending…
getElementByClassName
var nodes = document.getElementsByClassName('.first')
pending…
QuerySelectorAll
var nodes = document.querySelectorAll('first')
pending…
native code
var nodes = document.querySelectorAll('.first.listItem')
pending…
jQuery
var nodes = jQuery('.first.listItem')
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:

1 comment

karthick (revision owner) commented :

Comparing both jQuery and javascript native code

Add a comment