.is vs .parents vs. closest

Benchmark created by mekwall on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>

<div class="parent">
  <div class="child">
    <div class="grandchild"></div>
  </div>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
.is
(function() {
 return $('.grandchild').is('.parent .grandchild');
})();
ready
.parents
(function() {
 return $('.grandchild').parents('.parent').length > 0 ? true : false;
})();
ready
.closest
(function() {
 return $('.grandchild').closest('.parent').length > 0 ? true : false;
})();
ready

Revisions

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