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 trialViktoria Napolska
7,237 PointsChanging style of last and first Element after button clicked
Resolve this with code: const listUl = list.querySelector("ul"); const lis = listUl.children; var firstListItem = listUl.firstElementChild; var lastListItem = listUl.lastElementChild;
firstListItem.style.backgroundColor = 'lightskyblue'; lastListItem.style.backgroundColor = 'lightsteelblue'; function clear () { for (var i = 0; i < lis.length; i++) { lis[i].style.backgroundColor = "white"; } } document.addEventListener("click", () => { firstListItem = listUl.firstElementChild; lastListItem = listUl.lastElementChild; clear (); firstListItem.style.backgroundColor = 'lightskyblue'; lastListItem.style.backgroundColor = 'lightsteelblue'; })
3 Answers
Steven Parker
231,261 PointsThe HTML part of the code is missing, and there's nothing in the JavaScript that appears to be associated with any button(s).
You may need to explain your issue in more detail, and provide the whole code. The best way to share the entire project is to make a snapshot of your workspace and post the link to it here.
Viktoria Napolska
7,237 PointsI just try to show my solution of the teacher last task. Everything works. Sorry for bothering you) And thank you for help!)
Steven Parker
231,261 PointsSorry for my confusion, I thought you were looking for assistance with a problem.
Say, is that really your pic? I'd swear that was a photo of American actress Laura Harris.
Viktoria Napolska
7,237 PointsThank you, but it's really my photo))
deebird
7,558 Pointsdeebird
7,558 PointsWhere do you define list? Also please format your code, it makes it easier for us to help.