From the course: JavaScript: Enhancing the DOM (2013)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Cloning and removing nodes

Cloning and removing nodes

From the course: JavaScript: Enhancing the DOM (2013)

Start my 1-month free trial

Cloning and removing nodes

Making a copy of a node is called cloning and it can be useful if you want to move things around in your DOM. Let's say that you want to dynamically change the position of an existing element, the cloneNode method lets you make a copy of an existing node with our without its children. You can then reposition the node anywhere within the existing DOM. You can use removeChild to delete a note from the DOM, but you've gotta be careful with this one. RemoveChild works by removing a node from an existing parent. So if you want to use it, you've got to call it on the parent of the node you want to delete. So, let's take a look at this in an actual DOM. So, we've got our website right here. I'm going to pull up the console and I'm going to create a variable called my node and make it contain a node that's going to have the artist lists which is right here. So, I'm going to hit the magnifying glass and click on one of these items. You can see the breadcrumbs pointing to that element and when…

Contents