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:

Parameter Type Description
o? string | DomElementInfo | undefined The options object.
callback? ((el: HTMLDivElement) => void) | undefined A 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' });
});