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 trialMuhammad Khan
Courses Plus Student 8,772 Points**script.js:10 Uncaught TypeError: Cannot set property 'textContent' of null at script.js:10 **
I copied the code from teacher's note and paste in workspace save and run it but it gives error at line number 10. Please reply how to remove the error.
2 Answers
Cameron Childres
11,820 PointsHey Muhammad~
Check to see where you've linked your script in the HTML file. If the script is inserted above the h1 elements then it is loaded before they are and it won't be able to interact with them. Moving your script tag towards the bottom will solve this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Basics</title>
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<main>
<h1>Hello, JavaScript!</h1>
</main>
<script src="js/preview.js"></script>
</body>
</html>
Muhammad Khan
Courses Plus Student 8,772 PointsThanks Cameron. I got it.
Henry Spock
20,615 PointsHenry Spock
20,615 PointsCameron - this was driving me bats. Thank you for the answer.