Replacing existing nodes


show more Replacing existing nodes provides you with in-depth training on Developer. Taught by Ray Villalobos as part of the JavaScript: Enhancing the DOM show less
please wait ...

Replacing existing nodes

In the last movie, we learned how to move things around in the DOM by cloning and then removing a node. If you're just trying to replace an existing element then there's a function that does just that. replaceChild lets you take a node and replace it with another node. Since it's replacing a child you have to call it from the parent node, so it can be a bit confusing to use. This method is more convenient than cloning and replacing. You don't have to delete the original node. So, let's take a look at this in our project. So, I'm going to pull up the console. To replace a node, we need to get both the node we want to move and the one we want to replace.

So, I want to move this same list of artists, right here. I'm going to click on a magnifying glass. Click on one of these just to get the path right here. And these very useful bread crumbs that kind of tells us where we're at. So I know that this whole section is called featured artists. So ...

Replacing existing nodes
Video duration: 2m 32s 2h 3m Intermediate

Viewers:

Replacing existing nodes provides you with in-depth training on Developer. Taught by Ray Villalobos as part of the JavaScript: Enhancing the DOM

Subjects:
Developer Web
Software:
HTML JavaScript
Author:
please wait ...