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

Revision 15 of this benchmark created on


Description

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

update2: native document.querySelector no wrapped

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
Native querySelector
document.querySelector('#LOL')
ready

Revisions

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