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

Gbadebo Ogunbanjo
Gbadebo Ogunbanjo
9,720 Points

My Solution to Guil's closing challenge

const listDiv = document.querySelector('.list'); var ul = document.querySelector('ul'); const upButtons = ul.querySelectorAll('.Up'); const downButtons = ul.querySelectorAll('.Down'); const listUl = listDiv.querySelector('ul');

function redundantButton() { let funcul = document.querySelector('ul');

let topLi = funcul.firstElementChild; let topUpButton = funcul.firstElementChild.querySelector('.Up'); let bottomDownButton = funcul.lastElementChild.querySelector('.Down'); topUpButton.style.backgroundColor = "#fff"; topUpButton.style.border = "none"; bottomDownButton.style.backgroundColor = "#fff"; bottomDownButton.style.border = "none"; }

listUl.addEventListener('click', (event) => {

for (let i=0; i<ul.children.length; i++){ upButtons[i].style.backgroundColor = "#52bab3"; downButtons[i].style.backgroundColor = "#508abc";
}

redundantButton();

});