bitburner-src/utils/uiHelpers/removeElement.ts

27 lines
723 B
TypeScript
Raw Normal View History

/**
* For a given element, this function removes it AND its children
* @param elem The element to remove.
*/
export function removeElement(elem: Element | null) {
if (elem === null) {
// tslint:disable-next-line:no-console
console.debug("The element passed into 'removeElement' was null.");
return;
}
if (!(elem instanceof Element)) {
// tslint:disable-next-line:no-console
console.debug("The element passed into 'removeElement' was not an instance of an Element.");
return;
}
2018-07-08 07:11:34 +02:00
while (elem.firstChild !== null) {
elem.removeChild(elem.firstChild);
}
2018-07-08 07:11:34 +02:00
if (elem.parentNode !== null) {
elem.parentNode.removeChild(elem);
}
}