mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 09:43:54 +01:00
24 lines
605 B
TypeScript
24 lines
605 B
TypeScript
|
import { isString } from "../helpers/isString";
|
||
|
import { getElementById } from "./getElementById";
|
||
|
|
||
|
export function removeChildrenFromElement(el: string | null | Element) {
|
||
|
if (el === null) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
const elem: HTMLElement | Element = (isString(el) ? getElementById(el as string) : el as Element);
|
||
|
|
||
|
if (elem instanceof Element) {
|
||
|
while (elem.firstChild) {
|
||
|
elem.removeChild(elem.firstChild);
|
||
|
}
|
||
|
}
|
||
|
} catch (e) {
|
||
|
// tslint:disable-next-line:no-console
|
||
|
console.debug(e);
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
}
|