$("#id") vs $(document.getElementById) (v13)

Revision 13 of this benchmark created by Mark McDonnell on


Description

update: just so it was in there I added true native document.getElementById no wrapped inside jQuery.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<div id="LOL"></div>

Test runner

Ready to run.

Testing in
TestOps/sec
#id
$("#LOL");
ready
native
$(document.getElementById("LOL"));
ready
Sizzle
$("[id=LOL]");
ready
common mistake
$('div#LOL');
ready
native queryselectorall
$(document.querySelectorAll('#LOL'))
ready
native queryselector
$(document.querySelector('#LOL'))
ready
manual jquery collection
var $el = $(0);
$el.context = $el[0] = document.getElementById("LOL")
// $el == $(document.getElementById("LOL"))
ready
manual 2
var $el;
$el = $(document.getElementById("LOL"));
ready
Native 2
document.getElementById("LOL");
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.