Web APIs

Document.createElement()

Try the free JavaScript compiler

document.createElement creates an element that is not yet attached to the document. Set its properties and insert it when ready.

Formal Syntax & Structure

javascript syntaxjavascript
document.createElement(localName[, options])

Parameters & Attributes

NameTypeDescription
localNamestringElement local name.
optionsobjectOptional creation settings.

Return Value

Element

New detached element.

Working Example

Example Snippetjavascript
const item=document.createElement("li");item.textContent="Book";const list=document.createElement("ul");list.append(item);console.log(list.firstElementChild.textContent,item.isConnected);
JavaScript Reference