Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

47
Views
Where is the best place to put JavaScript in the HTML?

I am currently learning web development, and I'm currently learning JavaScript. And I have a question, where is the best place to put JavaScript (script tag) in the HTML?

7 months ago · Juan Pablo Isaza
2 answers
Answer question

0

Try to put all your JavaScript after your HTML code. The most common thing to see today is to place it in a separate file and use a script tag with a source file in it. <script src='main.js'></script>

Or just placing it within the script tag. <script>..code..</script>

The reason that you need these tags after your HTML, so on the last line of your body, is so that when you need to get something from the DOM, you know it has been loaded in already.

7 months ago · Juan Pablo Isaza Report

0

Here is an Answer from the w3schools website:

JavaScript in <head> or <body>
You can place any number of scripts in an HTML document.

Scripts can be placed in the <body>, or in the <head> section of an HTML page, or in both.

Here is the link to the mentioned answer:

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs