jQuery Parents vs Closest (v46)

Revision 46 of this benchmark created on


Description

Similar to parents vs closest, only this time testing when searching >1 level of the DOM ancestors and not matching the first element.

Preparation HTML

<div>
  <table id="end" class="end">
    <tr>
      <td>
        <ul>
          <li>
            1
          </li>
          <li>
            2
          </li>
          <li>
            3
          </li>
          <li>
            4
          </li>
          <li>
            5
          </li>
          <li>
            6
            <ul>
              <li>
                1
              </li>
              <li>
                2
              </li>
              <li>
                2
              </li>
              <li>
                3
                <ul>
                  <li>
                    1
                  </li>
                  <li>
                    2
                  </li>
                  <li>
                    3
                  </li>
                  <li id="start" class="start">
                    4
                  </li>
                  <li>
                    5
                  </li>
                </ul>
              </li>
              <li>
                4
              </li>
              <li>
                5
              </li>
            </ul>
          </li>
          <li>
            7
          </li>
          <li>
            8
          </li>
          <li>
            9
          </li>
          <li>
            10
          </li>
        </ul>
      </td>
    </tr>
  </table>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Parents
$(".start").parents("tr").first();
ready
Closest
$(".start").closest("tr");
ready
Parents by ID
$("#start").parents("tr").first();
ready
Closest by ID
$("#start").closest("tr");
ready
ID Parent:first
$("#start").parents("tr:first");
ready
ID Parent [0]
$('#start').parents('tr')[0]
ready
closest (with context)
$('.start').closest('tr', '.end')
ready
closest (with context and ID)
$('.start').closest('tr', '#end')
ready
ID Parent
$('#start').parent('tr')
ready
ID Parents [0]
$('#start').parent('tr')[0]
ready
ID Parents eq(0)
$('#start').parent('tr').eq(0)
ready

Revisions

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