Build: The Web

Adding JavaScript to HTML

Between the <script> and </script> elements in HTML, JavaScript code is placed. An HTML document can contain any number of scripts. Scripts can be placed in the <body>, the <head>, or both sections of an HTML page.
A JavaScript function is placed in the <head> section of an HTML page in this example.
A JavaScript function is placed in the <body> section of an HTML page in this example.
Create a .js script file, such as main.js, and place it in the head or body of the html document.
badge