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 Getting the First and Last Child

JORGE HERRANDO GARIJO
JORGE HERRANDO GARIJO
7,895 Points

Keeping the color on the first and last li

Hello. My first and last li have a backgroundColor defined. I am trying to keep the color always in the first and last li even when I change the position. I managed to get the color to the new first-last li, but I cannot make it disappear from the previous one. For any reason, the for loop doesn't go through the list items, yet the console says the backgroundColor it's been changed... Any suggestions?

https://w.trhou.se/alve62v4w1

1 Answer

Steven Parker
Steven Parker
231,269 Points

The "backgroundColor" should be a sub-property of the "style" and not a property of the element itself. And you probably want to just remove the color instead of making it black:

//  lis[i].backgroundColor = 'black';
    lis[i].style.backgroundColor = '';  // fixed
JORGE HERRANDO GARIJO
JORGE HERRANDO GARIJO
7,895 Points

Those little bugs!!

Yeah I was trying black just to let me see if it was working.

Thank youuu!