Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript DOM Scripting By Example Editing and Filtering Names Filter Invitees Who Have Not Responded

James Crosslin
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James Crosslin
Full Stack JavaScript Techdegree Graduate 16,745 Points

My 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?