HTML Script
JavaScript enhances HTML pages with greater dynamism and interactivity.
Online Examples
HTML <script>
Tag
The <script>
tag is used to define client-side scripts, such as JavaScript.
The <script>
element can either contain script statements or point to an external script file via the src
attribute.
JavaScript is most commonly used for image manipulation, form validation, and dynamic content updates.
The following script will output "Hello World!" to the browser:
Example
<script>
document.write("Hello World!");
</script>
Tip: To learn more about JavaScript, check out the JavaScript Tutorial!
HTML <noscript>
Tag
The <noscript>
tag provides alternative content for users when scripts are disabled in their browser or if their browser doesn't support client-side scripts.
The <noscript>
element can contain any element that could be found in the body of a regular HTML page.
The content inside the <noscript>
element is displayed only if the browser doesn't support scripts or if scripts are disabled:
Example
<script>
document.write("Hello World!")
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>
JavaScript Experience (From Our JavaScript Tutorial)
JavaScript Example Code:
JavaScript Directly Outputs to HTML:
document.write("<p>This is a paragraph.</p>");
JavaScript Event Response:
<button type="button" onclick="myFunction()">Click Me!</button>
JavaScript Handles HTML Styles:
document.getElementById("demo").style.color = "#ff0000";
HTML Script Tags
Tag | Description |
---|---|
<script> | Defines a client-side script |
<noscript> | Defines text to be shown in browsers that do not support scripting |