Skip to content

Node.createSpan method

Node › createSpan

Official

Creates a new <span> element.

Signature:

createSpan(o?: DomElementInfo | string, callback?: (el: HTMLSpanElement) => void): HTMLSpanElement

Parameters:

ParameterTypeDescription
o?DomElementInfo | stringThe options object.
callback?(el: HTMLSpanElement) => voidA callback function to be called when the element is created.

Returns: HTMLSpanElement — The created element.

Example:

document.body.createSpan({ text: 'foo' }, (span) => {
span.createEl('strong', { text: 'bar' });
});