Adding a New Element
Learn how to add an element on an existing web page via JavaScript.
We'll cover the following...
Adding a new element to a web page can be broken into three steps:
- Create the new element
- Set element properties
- Insert the new element in the DOM
For example, suppose you want to add the language “Python” to the list of languages on our page.
Let’s study each of these steps.
Creating the element
You’d create an element using the createElement()
method. This method is used on the document object and takes the tag of the new element as a parameter. This method also returns the element created as an object (here stored in a variable called pythonElement
).
Access this course and 1400+ top-rated courses and projects.