HTML DOM createElement()Method
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);
var t=document.createTextNode("CLICK ME");
btn.appendChild(t);
Output result:
Try it yourself »
Definition and Usage
The createElement() method creates an element by the specified name.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the createElement() method.
Syntax
document.createElement(nodename)
Parameter
| Parameter | Type | Description |
|---|---|---|
| nodename | String | Required. The name of the element to create. |
Return Value
| Type | Description |
|---|---|
| Element object | The created element node |
Technical Details
| DOM Version | Core Level 1 Document Object |
|---|
Other Extensions
Document Object