<script> tag. When an HTML document is loaded with the
Script tag Attributes and its Uses
Following is the basic syntax of using a
<script src="JS_FILE_URL" type="..."></script>
Similarly, we can use the
There are five attributes of script tag which are listed below in the table:
||It specifies whether the script should be executed asynchronously or not.|
||charset||It specifies the type of character encoding used in the script|
||It specifies whether the browser continues parsing the web page or not.|
||URL||It specifies the uniform source locator(URL) of a file that contains the script.|
In the HEAD element (
In the BODY element (
Let's cover all of this one by one along with code examples to help you understand them.
Let's put the script tag inside the HTML head element. The script placed inside the head element is loaded with the webpage and gets executed if any defined event occurs.
The code given below shows how to use the
<script> tag inside the
You can place a script tag inside the body element of an HTML document too. The script tag inside the body element runs when a web page starts loading in a web browser. Below is the code to show you how to place a
<script> element inside the
<body> element of an HTML document:
To link the external file, we can provide its location (URL) in the src attribute of the script tag.
type attribute is optional in the code example above.
<script> tags. Yes, we can use multiple
<script> tags in this case,
Now the question is, where should we put the above code in our HTML page. Should we put it inside the HEAD section of HTML code, or should we put it in the BODY section of our HTML page?
</body> tag or after the closing