element in dom (v4)

Revision 4 of this benchmark created on


Preparation HTML

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

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

Setup

var $el = $("#element");

Test runner

Ready to run.

Testing in
TestOps/sec
walker
var elem = $el[0], inDocument = false;

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

if (elem.nodeType === 9) {
  inDocument = true;
}
ready
object
$el.closest(document.documentElement);
ready
jQuery.contains
jQuery.contains(document.documentElement, $el[0])
ready

Revisions

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