document.head
JavaScript performance comparison
Info
How much faster is the HTML5 document.head DOM tree accessor compared to its old-school variant, document.getElementsByTagName('head')[0]?
Preparation code
<script>
document.head || (document.head = document.getElementsByTagName('head')[0]);
var headList = document.getElementsByTagName('head');
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
document.getElementsByTagName('head')[0] |
|
pending… |
document.head |
|
pending… |
querySelector |
|
pending… |
Live nodeList |
|
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 Mathias Bynens and last updated
- Revision 2: published by Charles Lehner
- Revision 3: published by kangax and last updated
- Revision 4: published by stefaan
- Revision 5: published
- Revision 6: published
2 comments
If this test is run on a browser which doesn’t support
document.headthen doesn’t it just usedocument.getElementsByTagName('head')[0]anyway which makes the results a bit meaningless?@David: It’s either that or failing the test in those browsers. This test only makes sense in browsers that support
document.head.