Replace an element
JavaScript version
const replace = (ele, newEle) => ele.parentNode.replaceChild(newEle, ele);
TypeScript version
const replace = (ele: Element, newEle: Element): Element | null => (ele.parentNode ? ele.parentNode.replaceChild(newEle, ele) : null);