[refactor] Moved 'removeElementById' to its own TS file

This commit is contained in:
Steven Evans
2018-07-05 13:36:02 -04:00
parent 488f947a5b
commit 875f7b4438
8 changed files with 31 additions and 17 deletions
+21
View File
@@ -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.
}
}