closest vs parents

JavaScript performance comparison

Test case created by X

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<p>
 <div>
   <form id="form4">
       <input id="test4">
     </form>
   <span>
     
   </span>
   <div>
     <form id="form1">
       <input id="test1">
     </form>
      <form id="form2">
       <input id="test2">
     </form>
      <form id="form3">
       <input id="test3">
     </form>
     </div>
   </div>
</p>  

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
alert($('#test3').parents('form').attr('id'));
pending…
closest
alert($('#test3').closest('form').attr('id'));
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