Skip to content

Instantly share code, notes, and snippets.

@AdhirRamjiawan
Last active October 20, 2017 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdhirRamjiawan/0fcad2ef373b75fc07c5eddc7abba2b8 to your computer and use it in GitHub Desktop.
Save AdhirRamjiawan/0fcad2ef373b75fc07c5eddc7abba2b8 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment