document.getElementById VS Jquery $('#') JQuery 2 (v34)

Revision 34 of this benchmark created by Pik_at on


Description

Comparison for $('#id') VS document.getElementById('id');

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<p id="foo">
  Test
</p>
<script type="text/javascript">
// cached native node
var nativeElem = document.getElementById("foo");
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
document.getElementById('id')
document.getElementById('foo');
ready
jQuery $('#id')
$('#foo');
ready
jQuery + native JS
$(document.getElementById('foo'));
ready
jQuery + cached native node
$(nativeElem);
ready
native JS + JQuery
var foo = document.getElementById('foo');
$(foo);
ready

Revisions

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