2018-07-08 05:42:58 +02:00
|
|
|
/**
|
|
|
|
* For a given element, this function removes it AND its children
|
|
|
|
* @param elem The element to remove.
|
|
|
|
*/
|
2021-05-01 09:17:31 +02:00
|
|
|
export function removeElement(elem: Element | null): void {
|
2021-09-05 01:09:30 +02:00
|
|
|
if (elem === null) {
|
|
|
|
// tslint:disable-next-line:no-console
|
|
|
|
console.debug("The element passed into 'removeElement' was null.");
|
2018-07-08 05:42:58 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
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.",
|
|
|
|
);
|
2018-07-08 05:42:58 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-07-08 05:42:58 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
while (elem.firstChild !== null) {
|
|
|
|
elem.removeChild(elem.firstChild);
|
|
|
|
}
|
2018-07-08 05:42:58 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
if (elem.parentNode !== null) {
|
|
|
|
elem.parentNode.removeChild(elem);
|
|
|
|
}
|
2018-07-08 05:42:58 +02:00
|
|
|
}
|