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

Anthony Ogounchi
.a{fill-rule:evenodd;}techdegree seal-36
Anthony Ogounchi
Full Stack JavaScript Techdegree Graduate 14,594 Points

Every invitees' name is hidden when I check the filtering box

The code seems to be working fine, no bugs, however when I check the filtering box every name get hidden. Here's the code :

const form = document.getElementById('registrar');
const input = form.querySelector('input');
const mainDiv = document.querySelector('.main');
const ul = document.getElementById('invitedList');

const div = document.createElement('div');
const filterLabel = document.createElement('label');
const filterCheckbox = document.createElement('input');

filterLabel.textContent = "Hide those who haven't responded";
filterCheckbox.type = 'checkbox';
mainDiv.insertBefore(div, ul);

// An event listener on the filterCheckbox allowing to filter out the 
// not confirmed invitees' names
filterCheckbox.addEventListener('change', (e) => {
    const isChecked = e.target.checked;
    const lis = ul.children;
    if (isChecked) {
        for (let i = 0; i < lis.length; i++) {
            let li = lis[i];
            if (li.className === 'responded') {
                li.style.display = '';
            } else {
                li.style.display = 'none';
    } else {
        for (let i = 0; i < lis.length; i++) {
            let li = lis[i];
            li.style.display = '';

function createLI(text) {
    const li = document.createElement('li');
    li.textContent = text;
    const label = document.createElement('li');
    label.textContent = 'Confirmed';
    const checkbox = document.createElement('input');
    checkbox.type = 'checkbox';

    const editButton = document.createElement('button');
    editButton.type = 'edit';

    const removeButton = document.createElement('button');
    removeButton.type = 'remove';

    return li;

form.addEventListener('submit', (e) => {
    const text = input.value;
    // Whenever the input var value is assign to text, 
    // we then want to empty the input var content. 
    input.value = '';
    const li = createLI(text);
// what happens when the checkbox is checked
ul.addEventListener('change', (e) => {
    const checkbox = event.currentTarget;
    const checked = checkbox.checked;
    const listItem = checkbox.parentNode.parentNode;
    if (checked) {
        listItem.className = 'responded';
    } else {
        listItem.className = '';
// what happens when the remove button is clicked
ul.addEventListener('click', (e) => {
    if (e.target.tagName === 'BUTTON') {
        const button = e.target;
        const li = e.target.parentNode;
        const ul = li.parentNode;
        if (button.textContent === 'remove') {
        } else if (e.target.textContent === 'edit') {
            const span = li.firstElementChild;
            const input = document.createElement('input');
            input.type = 'text';
            input.value = span.textContent;
            li.insertBefore(input, span);
            button.textContent = 'save';
        } else if (e.target.textContent === 'save') {
            const input = li.firstElementChild;
            const span = document.createElement('span');
            span.textContent = input.value;
            li.insertBefore(span, input);
            button.textContent = 'edit';
Steven Parker
Steven Parker
218,654 Points

If you make a snapshot of your workspace and post the link to it here, we could see the issue in operation.

2 Answers

Steven Parker
Steven Parker
218,654 Points

I did look the code over but didn't spot anything obvious, and I'd drop by and help if you were next door. :wink:
But if you upload the project into a workspace and provide a snapshot link, I can check it out that way.

Steven Parker
Steven Parker
218,654 Points

So did you ever resolve your issue?