Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript DOM Scripting By Example Adding and Removing Names Removing Names

Jess D'Souza
seal-mask
.a{fill-rule:evenodd;}techdegree
Jess D'Souza
Front End Web Development Techdegree Student 13,800 Points

Why not use the method ChildNode.remove() instead of using the method Node.removeChild() ?

Hi,

Just wanted to know if it is necessary to reference the parent child as depicted in the video.

Can't we just reference the li item as below and then remove the element completely? Is this an acceptable practice or is it not used due to certain limitations ?

invited_list.addEventListener("click", (event) => {

  if (event.target.tagName.toLowerCase() === "button") {
    let list_item = event.target.parentNode;
    list_item.remove();
  }
})

1 Answer

Steven Parker
Steven Parker
231,248 Points

The "remove" method doesn't have complete support on legacy browsers. But if that's not an issue for you, then it's functionally equivalent to "removeChild".