mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-25 02:32:55 +02:00
[refactor] Moved 'removeElementById' to its own TS file
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { getElementById } from "./getElementById";
|
||||
|
||||
//
|
||||
/**
|
||||
* Given its id, this function removes an element AND its children
|
||||
* @param id The HTML identifier to search for and remove.
|
||||
*/
|
||||
export function removeElementById(id: string) {
|
||||
try {
|
||||
const elem: HTMLElement = getElementById(id);
|
||||
while (elem.firstChild) {
|
||||
elem.removeChild(elem.firstChild);
|
||||
}
|
||||
|
||||
if (elem.parentNode) {
|
||||
elem.parentNode.removeChild(elem);
|
||||
}
|
||||
} catch (e) {
|
||||
// Probably should log this as we're trying to remove elements that don't exist.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user