2020-08-11 22:32:55 +02:00
|
|
|
export class HtmlUtils {
|
|
|
|
public static getElementByIdOrFail<T extends HTMLElement>(id: string): T {
|
|
|
|
const elem = document.getElementById(id);
|
|
|
|
if (elem === null) {
|
|
|
|
throw new Error("Cannot find HTML element with id '"+id+"'");
|
|
|
|
}
|
|
|
|
// FIXME: does not check the type of the returned type
|
|
|
|
return elem as T;
|
|
|
|
}
|
2020-09-16 18:38:50 +02:00
|
|
|
|
|
|
|
public static removeElementByIdOrFail<T extends HTMLElement>(id: string): T {
|
|
|
|
const elem = document.getElementById(id);
|
|
|
|
if (elem === null) {
|
|
|
|
throw new Error("Cannot find HTML element with id '"+id+"'");
|
|
|
|
}
|
|
|
|
// FIXME: does not check the type of the returned type
|
|
|
|
elem.remove();
|
|
|
|
return elem as T;
|
|
|
|
}
|
2020-08-11 22:32:55 +02:00
|
|
|
}
|