<script>: The HTML Script Element

I. Description

The HTML <script> element is used to embed Javascript directly into a webpage. The Javascript can be written between the opening and closing script tags. The <script> element may be a child of the <head> element, but it also may be placed anywhere in the <body> element.

II. Examples

<!DOCTYPE html>
<html>
    <head>
        <title>Script Element Example</title>
        <script>
            window.onload = function() {
                start();
            }
            function start() {
                let element = document.getElementById("javascript");
                element.value = "The content of this element was set using Javascript.";
            }
        </script>
    </head>
    <body>
        <h1>Script Element Example</h1>
        <p id="javascript"></p>
    </body>
</html>

This document was last updated: