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

Revision 22 of this benchmark created by Igor Reverser on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="LOL">
</div>
<script>
  var $el = $(0);
  var byId = document.getElementById.bind(document);
</script>

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
$el.context = $el[0] = document.getElementById("LOL")
// $el == $(document.getElementById("LOL"))
ready
binded document.getElementById
$(byId('LOL'))
ready
manual jquery collection from binded
$el.context = $el[0] = byId("LOL")
// $el == $(document.getElementById("LOL"))
ready

Revisions

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