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
Nathaniel Sem
5,870 PointsCode I created to remove specific item from the list as opposed to last item
removeItemButton.addEventListener("click", () => {
let ul = document.getElementsByTagName("ul")[0];
let li = document.querySelectorAll("ul li");
for ( let i = 0; i < li.length; i += 1 ) {
if ( addItemInput.value === li[i].textContent ) {
ul.removeChild(li[i]);
}
}
addItemInput.value = "";
});
When I tested this, it removed the item from the list that was typed in the input text box :).
1 Answer
Steven Parker
243,658 PointsThat would certainly be more useful.
You didn't mention which course you're working with, but if I remember correctly, as the course continues it achieves the same utility in an even more convenient manner by adding individual remove buttons to each list item.