DOM-Tricks

The good kind of manipulation

Creating new elements

Create a div

To create an element, the .createElement() method is used on the document object. The first parameter is the tag name of the element you want to create.

const elem = document.createElement('div');

Create a text node and set the content

To create a text node, the .createTextNode() method is used on the document object. The first parameter is optional and will set the content within the node.

const textNode = document.createTextNode('Hello World!');
Source for this page found on Github