jQuery Element Removed? (v84)

Revision 84 of this benchmark created on


Description

Checks if a DOM element has been removed; returns true if in DOM, false if removed.

Same stuff with document.body instead of documentElement, and one test case with documentElement for comparison.

Preparation HTML

<div id="element"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

Setup

var $removed = $('#element').remove();
    var $inDom = $('#tests');
    var removed = $removed[0];
    var inDom = $inDom[0];

Test runner

Ready to run.

Testing in
TestOps/sec
closest 'body' inDom
$inDom.closest('body');
ready
closest 'body' removed
$removed.closest('body');
ready
jQuery.contains inDom
jQuery.contains(document.documentElement, inDom);
ready
jQuery.contains removed
jQuery.contains(document.documentElement, removed);
ready
jQuery.contains body inDom
jQuery.contains(document.body, inDom);
ready
jQuery.contains body removed
jQuery.contains(document.body, removed);
ready
directly from body contains (inDom)
document.body.contains(inDom);
ready
directly from body contains (removed)
document.body.contains(removed);
ready

Revisions

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