Skip to content

createEl<K>

Official

Creates a new element.

Example:

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

Signature:

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

Parameters:

ParameterTypeDescription
tagKThe tag name of the element to create.
ostring | DomElementInfo | undefinedThe options object.
callback((el: HTMLElementTagNameMap[K]) => void) | undefinedA 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' });
});

Links to this page: