Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Learning JS Reply To: Learning JS

#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.