Skip to content

Node.createDiv method

Node › createDiv

Official

Creates a new <div> element.

Signature:

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

Parameters:

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

Returns: HTMLDivElementThe created element.

Example:

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