In this lesson you are going to learn:
Let’s start with a basic HTML page, like this one:
You can do this either in the <head> section, as follows:
Or or at the very bottom of the document just before the closing </body> tag, like so:
If you’re wondering whether it’s best to place your <script> tag in the <head> or the <body> tag, then you’re not alone.
Comments, comments, comments
When a comment spans over more than one line, you use /* Comment goes here */ to delimit a comment, just like you do in a stylesheet. Here’s how it’s done:
Here’s how it’s done:
Between the <script> and </script> tags either in the <head> or the <body> of your HTML document, add the following line of code, just after the comment:
Now save your work and run the page in your favorite browser. You’ll see an alert box popping up on page load. This is how the page looks in Firefox:
Make sure your <script>…</script> tags are there, that the text between the brackets is surrounded by quotes (‘ ‘), and that there is a semicolon ( ; ) at the end of the statement. Then try again.
Save all your documents and run the HTML page in the browser. You should view the same alert box popping up as in the previous example.