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

JavaScript JavaScript and the DOM (Retiring) Traversing the DOM Getting All Children of a Node with children

my buttons are not working

const toggelList = document.getElementById('toggleList'); const listDiv = document.querySelector('.list'); const descriptionInput = document.querySelector('input.description'); const descriptionP = document.querySelector('p.description'); const descriptionButton = document.querySelector('button.description'); const addItemInput = document.querySelector('input.addItemInput'); const addItemButton = document.querySelector('button.addItemButton'); const listUl = listDiv.querySelector('ul'); const list = listUl.children;

function attachListItemButton (li){ let up = document.createElement('button'); up.className = 'up'; up.textContent = 'Up'; li.appendChild(up); let down = document.createElement('button'); down.className = 'down'; down.textContent = 'Down'; li.appendChild(down);

let remove = document.createElement('button'); remove.className = 'remove'; remove.textContent = 'Remove'; li.appendChild(remove);

}

for (let i = 0 ; i < list.length; i +=1){ attachListItemButton(list[i]);

}

listUl.addEventListener('click', (event) => {
        if(event.target.tagName == 'BUTTON'){ 
        if (event.target.ClassName == 'remove'){
        let li = event.target.parentNode;
        let ul =  li.parentNode;
        ul.removeChild(li);

        } 

        if(event.target.tagName == 'UP'){ 
        let li = event.target.parentNode;
        let prevli = li.previousElementSibling;
        let ul =  li.parentNode;
        if (prevli){
        ul.insertBefore(li,prevli);
        }
        }  
        if(event.target.tagName == 'DOWN'){ 
        let li = event.target.parentNode;
        let nextli = li.nextElementSibling;
        let ul =  li.parentNode;
         if (nextli){
        ul.insertBefore(nextli,li);
        }

        }  }       });

toggelList.addEventListener('click', () => { if(listDiv.style.display == 'none'){ toggelList.textContent = 'Hide list'; listDiv.style.display = 'block'; }else{ toggelList.textContent = 'Show list'; listDiv.style.display = 'none';

} });

descriptionButton.addEventListener('click', () => { descriptionP.textContent = descriptionInput.value + " :";
descriptionInput.value = ''; });

addItemButton.addEventListener('click', () => { let ul = document.getElementsByTagName('ul')[0]; let li = document.createElement('li'); li.textContent = addItemInput.value; attachListItemButton(li); ul.appendChild(li); addItemInput.value = ''; });

The remove button is only one that working in your code, but the up and down will not able to run, because you make a condition that never going to be true which is: if(event.target.tagName == 'UP') and if(event.target.tagName == 'DOWN'), tagName method return HTML element, so you and there is no UP or Down html element, so you have to use className instead. The correction: if (event.target.className == 'up') and for down button (event.target.className == 'down') and those conditions should be under if (event.target.tagName == 'BUTTON'). :)

you have to check first if the target is button, if true, then check which class name that target has :)