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 trialyaakov
2,381 PointsIt doesn't work in my app.js file but works in console. Why?
const myList = document.getElementsByTagName('li');
for ( let i = 0; i < myList.length; i += 1 ) { myList[i].style.color = 'red'; }
Jonathan Grieve
Treehouse Moderator 91,253 PointsIt could be. The reason we write script tags as the last element(s) before the closing body tag is to ensurre that the browser has loaded all the DOM elements it needs before it looks for the JavaScript. That should rule out any exceptions for elements that don't yet exist on browser load.
1 Answer
yaakov
2,381 PointsThank you
yaakov
2,381 Pointsyaakov
2,381 PointsCan be a problem setting a:
<script src="app.js"> </script>
not in the last position in body?
Thank you