Creating Element in JavaScript
Creating Element
We can create a new element and put content inside it with the help of JavaScript. In other words, JavaScript has the capacity to create new elements.
The process for creating a new Element is:-
- document.createElement(element) creates a new element node.
- document.createTextNode(text) creates a new text node for that particular node.
- Then we have to assign that particular element to a node/another element. For this we have:-
- element.appendChild(newNode) adds a new child node to an element as the last child node.
- element.insertBefore(node1, node2) inserts node1 as a child before node2.