getElementById VS jQuery('#id') (v191)

Revision 191 of this benchmark created by Will on


Preparation HTML

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<p id="foo">
  Test
</p>
<p id="bar">
  bars</p>

Setup

function jQueryNested(id){
        return jQuery(document.getElementById(id));
    }
    
    function dollarNested(id){
        return $(document.getElementById(id));
    }
    
    getElByIdAlias = document.getElementById.bind(document)

Test runner

Ready to run.

Testing in
TestOps/sec
getElementById
$(document.getElementById('foo'));
ready
jQuery Selector
$('#foo');
ready
Custom Method
jQueryNested('foo');
 
ready
$ Custom Method
dollarNested('foo');
 
ready
jQuery Window Object
$('#foo');
$('#bar');
ready
realgetelementbyid
document.getElementById('foo');
ready
typeof
if(typeof (document.getElementById('foo')) === "undefined"){}
ready
Aliased GetEl
getElByIdAlias('foo');
ready

Revisions

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