#I keep getting this 'null' error when I click my button
4 messages · Page 1 of 1 (latest)
This happens because your <script> tag is in the wrong place... Move it to just before you close the body...
<script src="website2.js"></script>
</body>
</html>
Alternatively move it into the <head> and mark it with the defer attribute.
This happens because the browser reads/executes the file line by line so when it encounters the <script> tag it is immediately processed however the remainder of the HTML hasn't yet loaded so your document.getElementById(...) is actually coming back as NULL - it can't find the specified element because as I said it hasn't yet been loaded and effectively doesn't exist... So moving the script to the bottom (or the defer) causes the script to run AFTER the DOM is loaded.