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 trialBihari Lal
Front End Web Development Techdegree Student 169 PointsquerySlectorAll is not working
document.querySelectorAll is not working wht when i try to run the below code it doesnt change the color of all li to blue
document.querySelectorAll('li').style.color = "red";
1 Answer
Steven Parker
231,141 PointsThe "querySelectorAll" retuns a collection of elements, which has no "style" attribute of its own. But as shown in the example by Jun, you can use a loop to set the attribute of each element in the collection.
But it still won't change the color to blue unless you also change the color name from "red" to "blue".
Tai Jun Jie
Full Stack JavaScript Techdegree Graduate 23,907 PointsTai Jun Jie
Full Stack JavaScript Techdegree Graduate 23,907 PointsYou need to use a for loop to loop through all the "li" as querySelectorAll returns you an array.
Eg: