Home › Forums › JavaScript › Learning JS › Reply To: Learning JS
September 22, 2014 at 2:04 pm
#184156
Participant
Regarding you JS error, is this where you’re adding the script:
<script type='text/javascript' src='javascript/main.js'></script>
?
If so, the reason the browser can’t find your #comments
section because it doesn’t exist yet. As I mentioned in the demo pen, you need to either run the function on document ready, or put the script at the end of the page. This way, you can be sure that the browser has finished building the DOM before you start trying to work with it.
In most cases, putting the script at the end of the HTML (just before </body>
) is the easiest solution, but check out this S/O answer for more complete info on ways to solve this.