JQuery $('#id') vs jQuery(document.getElementById('id')); (v8)

Revision 8 of this benchmark created on


Description

Fastest way get a jQuery object of a DOM element of which I have the ID. document.getElementById has the advantage of not requiring escaping for special characters.

Preparation HTML

<div id="el">Some HTML element</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery('#id')
jQuery('#el');
ready
jQuery(document.getElementById('id'))
jQuery(document.getElementById('el'));
ready

Revisions

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