Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
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 up-
Alex Hort-Francis
12,924 Points2 Answers
-
Golas Makefs
Full Stack JavaScript Techdegree Student 285 Points1 Answer
-
Peter Huang
5,427 Points1 Answer
-
karan Badhwar
Web Development Techdegree Graduate 18,135 Points1 Answer
-
Samy TALBI
2,617 Points2 Answers
View all discussions for this video
Related 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