code: public static boolean isDetached(Node n) {
      assert n != null;
  
      if ("html".equalsIgnoreCase(n.getNodeName())) {
        return false;
      }
  
      return !getOwnerDocument(n).getBody().isOrHasChild(n);
    }
docs: Return whether a node is detached to the DOM.
  
  Be careful : This method works only on node that should be inserted within the body node.