JSFiddle - React, Tailwind, and code Playground

HTML

<body><div>
    <button  class="btn">BUTTON</button>
</div></body>
<button id="test">is button in document</button>

JavaScript

var btn = $('.btn');

btn.click(function(){
   btn.remove().wrap('<body/>'); 
});

$('#test').click(function(){
   alert(isInDom(btn));
});
    
    
function isInDom(obj) {
    var root = obj.parents('html')[0] 
    return !!(root && root === document.documentElement);
}