Using the Scripting Elements
script element defines scripts and control their execution. noscript defines what happens when a browser doesn't support scripting.
The script element is usually inside the head element, but you may use it anywhere in an HTML document.
Local Attributes of the script Element:
Attribute | Description |
---|---|
type | the type of the script. This attribute can be omitted for JavaScript scripts. |
src | the URL for an external script file. |
defer / async | how the script will be executed. |
charset | the character encoding of an external script file. |
Defining an Inline Script
inline means that you include the JavaScript statements in the HTML page.
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
<script>
document.write("This is from the script");
</script>
</head>
<body>
<a href="http://java2s.com">Visit java2s.com</a>
</body>
</html>
If you don't use the type attribute, the browser will assume that you are using JavaScript.
By default, scripts are executed as soon as they are encountered in the page.
Home
HTML CSS Book
HTML
HTML CSS Book
HTML
Document Structure:
- The doctype Element
- The html Element
- The head Element
- The body Element
- Setting the Document Title
- Setting the Base for Relative URLs
- Specifying Name/Value Metadata Pairs
- Declaring a Character Encoding
- Simulate an HTTP Header
- Defining CSS Styles
- Specifying the Media for a Style
- Denoting External Resources
- Defining a Favicon for Your Page
- Using the Scripting Elements
- Loading an External Scripting Library
- Deferring Execution of a Script
- Executing a Script Asynchronously
- The noscript Element
- Redirect the user to a different URL if it doesn't support JavaScript.
Related: