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 Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Perform: Appending and Removing Elements

Mike Salomone
Mike Salomone
15,610 Points

Why select ul and then remove child rather than just typing listItem.remove()?

title says it all.

2 Answers

John Coolidge
John Coolidge
12,614 Points

After browsing the Mozilla Development Network, I couldn't find any real difference between the two as far as browser compatibility was concerned. I do know that with removeChild() you can save the removed child in a variable to be appended later on.

var oldChild = parent.removeChild(child);

John

Ron Starski
Ron Starski
1,997 Points

removeChild() works on every browser while remove() is not that universal. On MDN remove() is marked as an experimental feature.