jQuery vs. Vanilla: 2 - Id selector

JavaScript performance comparison

Test case created


Some jQuery vs Vanilla tests based on Craig Bucklers article Native JavaScript Equivalents of jQuery Methods: the DOM and Forms.

Preparation code

<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>

<ul id="comments">
    <li class="comment">1</li>
    <li class="comment">2</li>
    <li class="comment">3</li>
    <li class="comment">4</li>
    <li class="comment">5</li>
    <li class="comment">6</li>
    <li class="comment">7</li>
    <li class="comment">8</li>
    <li class="comment">9</li>
    <li class="comment">10</li>
    <li class="comment">11</li>
    <li class="comment">12</li>

Preparation code output

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery 2.0
var c = $("#comments");
vanilla getElementById
var c = document.getElementById("comments");

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