SCRIPT tags that come in the form of:
<script> … </script>
You need to do this because the SCRIPT tags alert the browser program to start interpreting all the text between these tags as a script.
With this function, you can write out plain text or even HTML. This is the basic syntax.
<html> <body> <script> document.write("Hello World!") </script> </body> </html>
- Portability: Externally linked scripts allow you to use that code on multiple web pages. It also allows you to maintain the source code independently of your HTML
- Performance: externally linked scripts especially those loaded from another domain or server like a CDN (content delivery network) help reduce the number of HTTP requests. It also allows these filed to be cached locally by the web browser
Hello World From Script! Hello World From Embedded!
This is the contents of the HTML file:
This is the contents of script.js
let elems = document.getElementById("elem"); elems.innerHTML = "Hello World From Script!<br>";
The above script finds an element within the HTML file with an id of “elem” and changes the contents to Hello World From Script!
The embedded script then finds the same element within the HTML file with an id of “elem” and appends Hello World From Embedded! to the content.