Search w3schools.com:

SHARE THIS PAGE

DOM Document createElement() Method

Document Object Reference Document Object

Example

Create a button:

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

The result will be:


Try it yourself »

HTML elements often contains text. To create a button with text you must also create a Text Node which you append to the button element:

Example

Create a button with text:

var btn=document.createElement("BUTTON");
var t=document.createTextNode("CLICK ME");
btn.appendChild(t);

The result will be:


Try it yourself »

Definition and Usage

The createElement() method creates an Element Node with the specified name.

Read more about the Element Node object in our Element Node object reference.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The createElement() method is supported in all major browsers.


Syntax

document.createElement(nodename)

Parameters

Parameter Type Description
nodename String Required. The name of the element you want to create

Return Value

Type Description
Element object The created Element node

Technical Details

DOM Version Core Level 1


Document Object Reference Document Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]