$(doc.getElementById()) versus $("#id")

JavaScript performance comparison

Test case created by jcfant and last updated

Preparation code

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.min.js"></script>
<script>
var $15 = jQuery.noConflict();
</script>

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js"></script>
<script>
var $144 = jQuery.noConflict();
</script>

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
<script>
var $142 = jQuery.noConflict();
</script>


<div class="wrapper">
     <div class="innerWrapper">
          <div class="button">
               <a href="javascript:void(0)" id="button" class="buttonRef">
                    <span class="buttonText">Text</span>
               </a>
          </div>
     </div>
</div>
    

Preparation code output

<script> var $15 = jQuery.noConflict(); </script> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js"></script> <script> var $144 = jQuery.noConflict(); </script> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script> <script> var $142 = jQuery.noConflict(); </script> <div class="wrapper"> <div class="innerWrapper"> <div class="button"> <a href="javascript:void(0)" id="button" class="buttonRef"> <span class="buttonText">Text</span> </a> </div> </div> </div>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
getElement - 1.4.2
$142(document.getElementById("button"));
pending…
ID - 1.4.2
$142("#button");
pending…
getElement - 1.4.4
$144(document.getElementById("button"));
pending…
ID - 1.4.4
$144("#button");
pending…
getElement - 1.5
$15(document.getElementById("button"));
pending…
ID - 1.5
$15("#button");
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.

0 Comments