element in dom

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

<div>
  <div>
    <div>
      <div id="element"></div>
    </div>
  </div>
</div>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var $el = $("#element");
   
   
};
</script>

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
walker
var elem = $el[0], inDocument = false;

while (elem.nodeType === 1) {
  elem = elem.parentNode;
}

if (elem.nodeType === 9) {
  inDocument = true;
}
pending…
object
$el.closest(document.documentElement);
pending…
jQuery.contains
jQuery.contains(document.documentElement, $el[0])
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