GitHub 6219★

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);
Follow me on and to get more useful contents.