HTML DOM createElement() method
Example
Create a button:
var btn=document.createElement("BUTTON");
Output result:
Try it »
HTML elements often contain text. To create a button with specified text, you need to add a text node after the button element:
Example
Create a button with specified text:
var btn=document.createElement("BUTTON");
var t=document.createTextNode("CLICK ME");
btn.appendChild(t);
Output result:
Try it »
Definition and Usage
The createElement() method creates an element by a specified name
Browser support





All major browsers support the createElement() method
Syntax
document.createElement(
nodename
)
Parameters
| Parameters | Type | Description |
|---|---|---|
| nodename | String | Required. The name of the element to be created. |
Return Value
| Type | Description |
|---|---|
| Element object | The created element node |
Technical Details
| DOM version | Core Level 1 Document Object |
|---|
Document Object