code: public static void removeFromParent(Element elem) {
      if(elem != null && elem.getParentNode() != null) {
        elem.getParentNode().removeChild(elem);
      }
    }
docs: Remove an element from its parent, if defined.
  
  @param elem Element to remove