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 trialarik
5,791 PointsUncaught SyntaxError : Unexpected Token <
I used bracket text editor to write my code, and when I checked it using chrome dev tool it showed the message Uncaught SyntaxError : Unexpected Token <, which lead to the first line <! DOCTYPE html> What's the meaning of that? Is there anyone could give a hand to clarify? And This is the code I've written:
<!DOCTYPE html> <html> <head> <title>JavaScript and the DOM</title>
</head> <body> <h1 id="myHeading">JavaScript and the DOM</h1> <p>Making a web page interactive</p> <script type = "text/javascript"> const myHeading = document.getElementById( " myHeading" ); myHeading.addEventListener( "click", () => { myHeading.style.color = "red"; }); </script> </body> </html>
Thank you very much in advance.
3 Answers
0yzh
17,276 PointsHey Arik,
Looks like you have an extra space in your query for 'myHeading' -- document.getElementById( " myHeading" ).
// remove extra space
const myHeading = document.getElementById( "myHeading" );
Hope this helps
arik
5,791 PointsHey Hui Bui, Thank you very much for your help:) I am really a novice at programming, and never used jsfiddle before. I'll learn how to use that. Thank you for introducing me to jsfiddle:)
0yzh
17,276 PointsNo problem! glad I could help.
arik
5,791 PointsI've removed the white space, but the console still send the same error message. What I don't understand is, why I can still launch it using bracket's live preview, but when I tried to use console it sent the error message...What could be wrong?
0yzh
17,276 PointsHey Arik,
Here's a working jsfiddle example of the code you provided and extra space removed. You can do a code compare to the working example and see what else may be causing the error.