Introduction:

In this article we are going to explain what is <script> tag in html or why use script tag in HTML or how to use script element in html or how to place a script within your HTML document with example.

Description:

HTML script tag is used to declaring client-side script such as JavaScript. It allows you to place a script within your HTML document.

JavaScript is used for image manipulation, form validation, and dynamic content.

The syntax of script tag is given below:

<script>
    //code to be here
</script>


Usage of script tag

There can be two usage of HTML script tag:

Ø  to embed script code

Ø  to link script file

Example of HTML to embed script code

The script tag can be used within <body> or <head> tag to embed the scripting code. Let's see the example to have script tag within HTML head.

 

 <!DOCTYPE html>
<html>
<head>
    <title>This is the example of script tag</title>
 
    <script type="text/javascript">
        function msg() {
            alert("Hello sqltutorialspoint");
        }
    </script>
     
</head>
<body>
    <p>The HTML Script tag allows you to <br />
    place a script within your HTML documents</p>   
</body>
</html>

 

 Example of HTML to link script file

The script tag can be used to link external script file by src attribute. It should be used within the <head> tag but If you want it can use in within body tag.

 <!DOCTYPE html>
<html>
<head>
    <title>This is the example of script tag</title>
 
    <script src="Scripts/jquery-1.8.2.js"></script>  
    
</head>
<body>
    <p>The HTML Script tag allows you to <br />
    place a script within your HTML documents</p>   
</body>
</html>

I hope this article will help to you after reading.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like