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

Revision 16 of this benchmark created by altryne on


Preparation HTML

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

<div id="LOL"></div>
<script>
  var $el = $(0);
</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
native chrome global var from ID
if(LOL){
$el.context = LOL
}
ready

Revisions

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