HTML DOM createElement()Method

Document 对象参考手册Document Object

Example

Create a button:

var btn=document.createElement("BUTTON");

Output result:


Try it yourself »

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 yourself »

Definition and Usage

The createElement() method creates an element by the specified name.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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


Document 对象参考手册Document Object

Other Extensions