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) The Browser Environment Thinking Globally

Hugo Paigneau
Hugo Paigneau
4,253 Points

Got an error when i ue the document.getElementById('myHeading').style.color = 'purple' functon

The consol told me this : TypeError: document.getElementById(...) is null[En savoir plus] scripts.js:1:1 <anonyme>

Vic Mercier
Vic Mercier
3,276 Points

Could you give me More information about what you are doing \Pouvez-vous me donner plus d'info

2 Answers

Steven Parker
Steven Parker
231,008 Points

This error would seem to indicate that there is no element with an ID of "myHeading".

This can happen if the JavaScript code is executed before the page is fully loaded. Is the <script> tag the very last thing in the body of the HTML?

Close down the browser that has the console open and the work-space then re-fresh the tutorial page.

I had the same issue and did this and now it works.

:)