X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM 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.


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


Document Object Reference Document Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook