$(doc.getElementById()) versus $("#id")
JavaScript performance comparison
Info
Testing getElementById() and then passing the node element to jQuery versus just looking up the item by $("#ID");.
Preparation code
<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.min.js"></script>
<script type="text/javascript">
var $15 = jQuery.noConflict();
</script>
<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
var $144 = jQuery.noConflict();
</script>
<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
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
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
getElement - 1.4.2 |
|
pending… |
ID - 1.4.2 |
|
pending… |
getElement - 1.4.4 |
|
pending… |
ID - 1.4.4 |
|
pending… |
getElement - 1.5 |
|
pending… |
ID - 1.5 |
|
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:
- Revision 1: published by jcfant and last updated
- Revision 3: published
- Revision 4: published
- Revision 6: published by newbreedofgeek
- Revision 7: published
- Revision 8: published
- Revision 9: published by dmitrys
- Revision 10: published
0 comments