This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
htmlElement.id = (elementId) ? elementId : ""; | |
htmlElement.innerHTML = (innerHTML) ? innerHTML : ""; | |
if (attributes) { | |
for (let attr of attributes) | |
htmlElement.setAttribute(attr.key, attr.value); | |
} | |
return htmlElement; | |
} |