getElementsByTagname("a")[0] vs. querySelector("a")
JavaScript performance comparison
Info
Tests how quickly you can iterate through multiple elements on the page using getElementsByTagName("a") vs. querySelector("a").
Preparation code
<ul>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
</ul>
<script>
var list, result, i, len;
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Using getElementsByTagName() |
|
pending… |
Using querySelector() |
|
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 Nicholas C. Zakas
- Revision 4: published by Scott Sauyet
- Revision 7: published by Jorge Chamorro
- Revision 9: published by Jorge Chamorro
- Revision 11: published by vamp
- Revision 12: published
- Revision 13: published
0 comments