English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM createElement() method

HTML DOM Document Object

createElement()method to create an HTML element node with a specified name.

UsecreateTextNode()method to create a text node.

After creating the component, useelement.appendChild()orelement.insertBefore()Method to insert it into the document.

Syntax:

document.createElement(name)
var newElem = document.createElement("h"3");
Test and see‹/›

Browser Compatibility

All browsers fully support the createElement() method:

Method
createElement()YesYesYesYesYes

Parameter Value

ParameterDescription
nameA string containing the element name

Technical Details

Return Value:An Element object representing the created Element node
DOM Version:DOM Levels1

More Examples

Create a <p> element and append it to a <div> element:

var para = document.createElement("p");
var newContent = document.createTextNode("Hi there and greetings!");
para.appendChild(newContent);
document.getElementById("myDiv").appendChild(para);
Test and see‹/›

HTML DOM Document Object