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 trialabdo wsdsla
Courses Plus Student 306 PointsRemove the removeMe element from the parent element.
Remove the removeMe element from the parent element. ???
const removeMe = document.querySelector('.remove_me');
let parent = .parentNode;
<!DOCTYPE html>
<html>
<head>
<title>Parent Traversal</title>
</head>
<link rel="stylesheet" href="style.css" />
<body>
<ul>
<li>Hello</li>
<li>Hi</li>
<li class="remove_me">Good bye!</li>
<li>Howdy</li>
</ul>
<script src="app.js"></script>
</body>
</html>
7 Answers
Sydney Hill
4,115 Pointsparent.removeChild(removeMe);
f lsze
8,021 PointsHi, In order to select the parent, you need to call .parentNode
on the removeMe
element. Like so:
let parent = removeMe.parentNode;
Once that is selected you will be able to proceed to the next step of removing the removeMe
element. See Sydney Hill's answer if you also need help with that.
Robert Dischinger
17,702 Pointsconst removeMe = document.querySelector('.remove_me'); let parent = removeMe.parentElement; parent.removeChild(removeMe);
Artur Pogosyan
11,110 Pointsconst removeMe = document.querySelector('.remove_me'); let parent = removeMe.parentNode;
Paulette Fenderson
3,055 Pointsvar removeMe = document.querySelector('.remove_me'); var parent = removeMe.parentNode; parent.removeChild(removeMe);
Sydney Hill
4,115 PointsYes Filip Olszewski is correct on the first step! :)
Raul Gonzalez
2,929 Pointsvar removeMe = document.querySelector('.remove_me'); var parent = removeMe.parentNode; parent.removeChild(removeMe);
Vahe Gharagiozyan
10,088 PointsThis works, thank you Raul
abdo wsdsla
Courses Plus Student 306 Pointsabdo wsdsla
Courses Plus Student 306 Pointsgot it,,thank you :)