Skip to content

Window.createEl method

Window › createEl

Official

Creates a new element.

Signature:

createEl(tag: K, o?: DomElementInfo | string, callback?: (el: HTMLElementTagNameMap[K]) => void): HTMLElementTagNameMap[K]

Parameters:

ParameterTypeDescription
tagKThe tag name of the element to create.
o?DomElementInfo | stringThe options object.
callback?(el: HTMLElementTagNameMap[K]) => voidA callback function to be called when the element is created.

Returns: HTMLElementTagNameMap[K] — The created element.

Example:

createEl('p', { text: 'foo' }, (p) => {
p.createEl('strong', { text: 'bar' });
});