Skip to content

createEl<K>

Official

Creates a new element.

Signature:

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

Parameters:

Parameter Type Description
tag K The tag name of the element to create.
o? DomElementInfo | string The options object.
callback? (el: HTMLElementTagNameMap[K]) => void A 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: