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
Maximilian Tan
5,570 PointsRemoving 'up' or 'down' buttons as elements traverse up/down the list (firstElementChild video tutorial)
Hi,
I'm referring to the additional challenge posed at the end of the above-mentioned video where the up/down buttons will not be shown as the elements in the list reaches the top/bottom of the list.
The buttons could be removed for the first item of the list. However, as this element proceeds downwards, the 'up' button still does not show, and the element that is now on the top of the list still retains its up button. My code block as shown:
for (i=0; i < lis.length; i++){
attachListItemButton(lis[i]);
if(lis[i] == firstListItem){
let upbutton = lis[i].getElementsByClassName('up');
upbutton[0].parentNode.removeChild(upbutton[0]);
}
}
Please help!!
Thanks!
1 Answer
Steven Parker
243,656 PointsThis snippet doesn't show how "firstListItem" is assigned. Does it get reset as items are moved? Also, at most this code only removes a button, it would not create one if the item is moved down.
You may need to show more of the code for the actual situation to be clear. Even better, make a snapshot of your workspace and post the link to it here.