Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM (Retiring) Getting a Handle on the DOM Select a Page Element By Its ID

Can't make the heading red

const myHeading = document.getElementById('myHeading');

myHeading.addEventListener('click', () => { myHeading.style.color = 'red';
});

what is wrong with my code. I can't get the h1 heading to become red!

2 Answers

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,107 Points

My guess is that myHeading n your HTML is not an id or is spelled differently. Could you post your html code as well?

sure here it is: <!DOCTYPE html> <html> <head> <title>JavaScript and the DOM</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <h1 id="myHeading">JavaScript and the DOM</h1> <p>Making a web page interactive</p> <sciprt src="app.js"></sciprt> </body> </html>

shashi7
shashi7
11,032 Points

Hi, Your script tag is misspelt.

 <sciprt src="app.js"></sciprt> 

Should be

<script src="app.js"></script> 

It should work now.

Thank you very much!!!!