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

My code on with the same solution doesn't work.

Hi Guys!

I would like to know how come my work doesn't for the down button, but I have copied Guils answer.

http://w.trhou.se/ry8lcczmyi

My code doesn't work if do it like this:

    if(event.target.className === 'down'){
      let nextLi = li.nextElementSibling;
      console.log(nextLi);
      if(nextLi){
        ul.insertBefore(li, nextLi);
      }
    }

But if I add a nextSibling on the insertBefore property it works:

    if(event.target.className === 'down'){
      let nextLi = li.nextElementSibling;
      console.log(nextLi);
      if(nextLi){
        ul.insertBefore(li, nextLi.nextSibling);
      }
    }

I just want to know how come the other one doesn't and the other does?

Thanks!

1 Answer

Steven Parker
Steven Parker
243,656 Points

You have the arguments reversed in the call to insertBefore.

So instead of this:

        ul.insertBefore(li, nextLi);

You would write this (as Guil did):

        ul.insertBefore(nextLi, li);

Thanks Steven for your help! It works now.

Cheers!