JavaScript JavaScript and the DOM Traversing the DOM Getting the First and Last Child

Jesse Vorvick
Jesse Vorvick
Full Stack JavaScript Techdegree Student 3,362 Points

Solution to challenge... please critique!

I finally did it, and it took many hours. Please let me know how it is. Somehow I have this nagging feeling I did it the hard way.

https://w.trhou.se/15vhwyjtnm

Thank you!

1 Answer

Sam Stickle
Sam Stickle
Full Stack JavaScript Techdegree Student 23,244 Points

Hi, Jesse Vorvick!

Somehow I have this nagging feeling I did it the hard way.

I often have that same feeling. :)

If I understand the objective of this code challenge correctly, you want to not show the ‘up’ or ‘down’ buttons when they are not needed.

Your solution works fine to accomplish that.

Another approach would be to control the visibility of the buttons through CSS. You could use selectors to identify whether a list item was at the top or the bottom of the list. And then control the visibility of the unneeded button that is inside that list item.

A couple of ways to control whether something shows: “display: none” would hide an element and also remove it from the page flow. “visibility:hidden” would hide an element while still filling its place on the page (keeping alignment etc. the same).