Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
When working with HTML, you'll often set class attributes on elements and apply styles to them with CSS. The document object provides a way to select elements in the DOM with a given class name with document.getElementsByClassName()
.
Further Reading and Related Videos
- document.getElementsByClassName() β MDN
- for...of β MDN
- forβ¦of loop. Should I use const or let?
- For Loops, For...Of Loops and For...In Loops in JavaScript
Exercise
Inside the for...of
loop, the variable highlight
is assigned a different value. Log the highlight
variable to the console to view the collection of returned elements.
for ( const highlight of highlights ) {
highlight.style.backgroundColor = 'cornsilk';
console.log(highlight);
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up