English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
document.createElement(name)
var newElem = document.createElement("h"3");Test and see‹/›
All browsers fully support the createElement() method:
Method | |||||
createElement() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
name | A string containing the element name |
Return Value: | An Element object representing the created Element node |
---|---|
DOM Version: | DOM Levels1 |
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‹/›