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 trialBrian Ball
Treehouse Project ReviewernextElementSibling
if (event.target.className == 'down') {
let li = event.target.parentNode; // because we want to move up... prev sibling
let nextLi = li.nextElementSibling;
let ul = li.parentNode;
if (nextLi) {
ul.insertBefore(li, nextLi);
}
}
When the event of clicking the down button occurs, the list item to go down? What am I doing wrong?
2 Answers
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsHey Brian , suppose in your example , 'li' is at second position and 'nextLi' is at first position (as 'nextLi' is above 'li'). So , what you are doing is extracting 'li' and 'nextLi' and putting 'li' and 'nextLi' at the same postion where they were initially .
In order to bring 'nextLi' which is at first position down to second position , you have to insert it before 'li' .
So , you just need to replace your 'li' with 'nextLi' and 'nextLi' with 'li' within 'insertBefore' method .
if (event.target.className == 'down') {
let li = event.target.parentNode;
let nextLi = li.nextElementSibling;
let ul = li.parentNode;
if (nextLi) {
ul.insertBefore(nextLi, li);
}
}
Hope it helps :)
Happy Coding
Brian Ball
Treehouse Project ReviewerThanks Aakash, I will able to use what you shared to move on!
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsMost welcome bro :) . Keep coding . We all do those mistakes , that's the way we learn
remon
10,620 Pointsremon
10,620 PointsThank You Aakash it helped!!