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 trialJames Crosslin
Full Stack JavaScript Techdegree Graduate 16,882 PointsMy solution was different
So I didn't like that Guil wanted to insert a checkbox with javascript that will be available on page load anyway.Β It seems more error-prone than simply putting it into the HTML since it's not going anywhere. So I added mine to the HTML, added a class to my CSS that I called hidden
that has display property set to none so that I could toggle instead of add yet another if else clause (I hate how wordy if else clauses get), then used this as my event listener:
const filterContainer = ul.previousElementSibling;
filterContainer.addEventListener("change", (e) => {
//gets the children of ul (which are all our list items) and makes them an array and
//filters li that don't have the responded class into an array
[...ul.children].filter( li => !li.classList.contains("responded"))
//hides each element stored in the filter array
.forEach( li => li.classList.toggle("hidden"));
});
Does anyone like this approach more as a cleaner solution or is it just me? Is it too abstract?