The great thing about JavaScript is that you can do a lot of things programmatically.
One of these things is being able to create new DOM elements.
This is how libraries like React and Vue work, they internally manage state and then manipulate the DOM by editing, creating and deleting elements from the DOM.
In this post, we'll learn how to create new DOM elements using JavaScript.
Creating a new DOM element
To create a new DOM element, we can use the document.createElement method.
This method takes a string as an argument, which is the name of the element we want to create.
JAVASCRIPT
const element = document.createElement("div");
Once we have our element, we can do things like changing the text inside of it, the background color, or add a class to it: