27
Showerthought: I keep seeing new people put their JavaScript at the top of the HTML file
My friend was trying to make a button change color on his site for a class in Austin, and it just wouldn't work. I looked at his code and his script tag was in the head, so the button didn't exist yet when the script ran. Moved it to the bottom of the body and it worked right away. How many other simple things like this trip people up at the start?
2 comments
Log in to join the discussion
Log In2 Comments
skylerc8623d agoTop Commenter
Actually, putting scripts up top is better practice.
6
the_julia23d ago
Oh man, that is such a classic. I must have done that exact same thing a dozen times when I was starting out. It feels like a right of passage, honestly. You just get so excited to make something work that you forget the page builds from top to bottom. It's a simple fix but it really makes you feel it when it clicks.
4