jQuery parents().hasClass() vs parentsUntil()

JavaScript performance comparison

Revision 11 of this test case created

Info

parents.hasClass vs closest

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div class="parent1">
  <div class="parent2">
  </div>
  <div class="parent2">
    <div class="parent3">
      <div class="parent4">
      </div>
      <div class="parent4">
        <div class="parent5">
          <div class="parent6">
            <div class="parent7">
            </div>
            <div class="parent7">
              <div class="parent8">
                <div class="parent9">
                  <div class="parent10">
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="parent3">
      </div>
    </div>
  </div>
</div>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
parents and hasClass
jQuery('.parent9').parents().hasClass('parent3')
pending…
closest
jQuery('.parent9').closest('.parent3')
pending…
parents(select)
jQuery('.parent9').parents('parent3')
pending…
many parent
jQuery('.parent9').parent().parent().parent().parent().parent().parent()
pending…
find
jQuery('.parent9').parents().find('parent3')
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment