jQuery exists() vs length

Benchmark created by Kirk on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
jQuery.fn.exists = function(){return this.length>0;}
</script>
<div class="foo"></div>

Test runner

Ready to run.

Testing in
TestOps/sec
exists()
if ($('.foo').exists()) {
  return true;
}
ready
length
if ($('.foo').length) {
  return true;
}
ready

Revisions

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