2018-07-05 19:23:12 +02:00
|
|
|
/**
|
|
|
|
* Returns a reference to the first object with the specified value of the ID or NAME attribute,
|
|
|
|
* throwing an error if it is unable to find it.
|
|
|
|
* @param elementId The HTML ID to retrieve the element by.
|
|
|
|
* @throws {Error} When the 'elementId' cannot be found.
|
|
|
|
*/
|
2021-05-01 09:17:31 +02:00
|
|
|
export function getElementById(elementId: string): HTMLElement {
|
2021-09-05 01:09:30 +02:00
|
|
|
const el: HTMLElement | null = document.getElementById(elementId);
|
|
|
|
if (el === null) {
|
|
|
|
throw new Error(`Unable to find element with id '${elementId}'`);
|
|
|
|
}
|
2018-07-05 19:23:12 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return el;
|
2018-07-05 19:23:12 +02:00
|
|
|
}
|