Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Adding Elements | DOM Manipulation
Advanced JavaScript Mastery
course content

Course Content

Advanced JavaScript Mastery

Advanced JavaScript Mastery

1. Classes
2. DOM Manipulation
3. Events and Event Handling
4. Asynchronous JavaScript and APIs

bookAdding Elements

Manipulating the DOM often involves dynamically creating and adding new elements to the document or removing existing elements based on user interactions. Here, we will consider how to create and add elements dynamically.

Creating New Elements and Adding Them to the DOM

JavaScript provides methods like createElement(), appendChild(), and insertBefore() to create new elements and add them to the DOM.

CreateElement()

The createElement() method creates a new HTML element but doesn't add it to the DOM until you explicitly do so with methods like appendChild() or insertBefore().

AppendChild()

The appendChild() method adds a new child element to the end of a parent element's list of children. It's commonly used for adding elements to the bottom of a section, list, or container.

html

index

css

index

js

index

copy

InsertBefore()

The insertBefore() method inserts a new element before a specified existing child element, allowing for more precise placement within a parent.

html

index

css

index

js

index

copy
1. What does the `createElement()` method do?
2. What will the following code do?
What does the `createElement()` method do?

What does the createElement() method do?

Select the correct answer

What will the following code do?

What will the following code do?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 9
We're sorry to hear that something went wrong. What happened?
some-alt