Let\'s say that I define an element
$foo = $(\'#foo\');
and then I call
$foo.remove()
from some event. My
Probably the most performative way is:
document.contains(node); // boolean
This also works with jQuery:
document.contains($element[0]); // var $element = $("#some-element")
document.contains(this[0]); // in contexts like $.each(), `this` is the jQ object
Source from MDN
Note:
- Internet Explorer only supports contains() for elements.