jquery id selectors

Benchmark created on


Description

test performance for selectors with id

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var html = "<p><div id="40">";
for ( var i = 0; i < 500; i++ ) {
  html += '<a id="'+i+'"><span>'+i+'</span></a>';
}
html += "</div></p>";
document.write( html );
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
select over attribut
$('a[id="250"]');
ready
select over tag+hash
$('a#250');
ready
select over hash
$('#250');
ready
by hash + parent
$('#250').parents('div');
ready
by hash + find
$('#250').find('span');
ready
by hash + children
$('#250 span');
ready

Revisions

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