Fastest ID selector (v2)

Revision 2 of this benchmark created by Garfie on


Description

Test to see which is faster, looking up ID using jquery css ID selector (#) or looking up element using doc.getElementByID and passing that to Jquery.

Preparation HTML

</<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="parent">
  <div id="subParent">
    <div id="d1">
      d1
    </div>
    <div id="d2">
      d1
    </div>
    <div id="d2">
      d1
    </div>
    <div id="d3">
      d1
    </div>
  </div>
</div>

<div id="console"> </div>

Test runner

Ready to run.

Testing in
TestOps/sec
jquery ID selector
var d = $('#d1');
 
ready
pass js obj to jQuery
var e = $(document.getElementById('d1'));
 
ready
Multiple Elements JS
var e = $(document.getElementById('d2'));
ready

Revisions

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

  • Revision 1: published by Meshan on
  • Revision 2: published by Garfie on