Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
export class HtmlElementFactory {
// method overloading - sort off... pretty weird
static CreateGeneric(elementName: string): HTMLElement;
static CreateGeneric(elementName: string, elementId: string,
innerHTML:string,attributes: Array<HtmlElementAttributes>) : HTMLElement;
static CreateGeneric(elementName: string, elementId?: string,
innerHTML?:string, attributes?: Array<HtmlElementAttributes>) : HTMLElement {
var htmlElement = document.createElement(elementName); = (elementId) ? elementId : "";
htmlElement.innerHTML = (innerHTML) ? innerHTML : "";
if (attributes) {
for (let attr of attributes)
htmlElement.setAttribute(attr.key, attr.value);
return htmlElement;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment