HTML <script> Tag
<!DOCTYPE html>
<title>My Example</title>
<time id="msg"></time>
<script>
document.getElementById("msg").innerHTML = Date();
</script>
The above example demonstrates usage of the <script>
element.
The <script>
element allows you to add scripts to your HTML documents. JavaScript is the default script type, however, it could be any language. If the script is not JavaScript, you can provide the language by using the type
attribute.
Attributes
Attributes supported by the <script>
element (on top of the global HTML attributes) are:
src
- Address of an external resource containing the script.
type
- Type of embedded resource.
charset
- Character encoding of the external script resource.
async
- Execute script asynchronously. Only to be used if the
src
attribute is used. defer
- Defer script execution. Only to be used if the
src
attribute is used. crossorigin
- How the element handles crossorigin requests
<samp>