Skip to content

Node.createDiv method

Node › createDiv

Official

Creates a new <div> element.

Signature:

createDiv(o?: DomElementInfo | string, callback?: (el: HTMLDivElement) => void): HTMLDivElement

Parameters:

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

Returns: HTMLDivElement — The created element.

Example:

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