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 Solution: Using nextElementSibling

Down button doesn't do anything, but no error in the console

My down button doesn't do anything, but there isn't an error in the javascript conosle. How do I fix this? My workspace is https://w.trhou.se/hhhootx4qe I think I followed the solution but it still doesn't do anything.

Hmm, now I'm really confused, I copied and pasted your code into my code and it still says the same error

Cameron Childres
Cameron Childres
11,820 Points

Here's my version of your workspace: https://w.trhou.se/7yxok55def

You can click "fork snapshot" in the top right to get a version you can preview and edit. Check to see what differences there are between this and the code you're running. I know we're going back and forth a lot here, but if you post another snapshot I'm happy to take a look and see what's going wrong.

It worked! I'm not sure what happened, maybe I just missed it? I don't think I edited my code after you posted that link. Thanks so much! I just marked your answer as best answer.

1 Answer

Cameron Childres
Cameron Childres
11,820 Points

Hey babyoscar,

I think the problem is between line 23 and 24 -- you're missing a } to close the previous if statement. As it stands your "down" statement is nested inside of the "up" statement, so the code will only run if the button had both the "up" and "down" classes.

Hmm, I tried doing that, and now it says Uncaught Syntax Error: missing ) after argument list app.js:34 Maybe I did it wrong? My workspace is https://w.trhou.se/hgyeszc65q

Cameron Childres
Cameron Childres
11,820 Points

It looks like there was also an extra } down below, on line 34. When I take it out it the down button works for me and doesn't produce any errors:

 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.className == 'up') {
      let li = event.target.parentNode;
      let prevLi = li.previousElementSibling;
      let ul = li.parentNode;
      if (prevLi) {
      ul.insertBefore(li, prevLi);
      }
    }
       if (event.target.className == 'down') {
        let li = event.target.parentNode;
        let nextLi = li.nextElementSibling;
        let ul = li.parentNode;
        if (nextLi) {
         ul.insertBefore(nextLi, li);
        }
      }
    }
  }
);