How to add JavaScript to web page

JavaScript is embedded into an HTML file. The browser reads HTML files and interpreter HTML tags.

The JavaScript code given information about by using the HTML tags ……………..

The tag consists two impotent attribute LANGUAGE and TYPE. The LANGUAGE attribute specifies the scripting language to be used.

The syntax of script tag is:
<script language="JavaScript" type="text/JavaScript">
..................
..................
<//JavaScript code
</script>

The script element can go anywhere in the document but the most common place for script are in the head of the document and the end of the body section.

Script can be Internal and external.

Internal Script

Internal Script are placed either in head or body section of document.

When you want the script to run on triggering an event such as clicking button or pressing a key place the <script> tag in the head section of the web page.

<head> element us always read first due to the sequential nature of the web page.

Example:-
<html>
<head>
<title> Internal script</title>
<script language="JavaScript" type=" text/JavaScript">

// JavaScript code

</script>
</head>
<body>
.........
.........
</body>
</html>

When you want to execute scrip as the page loads so place the <script> tag inside the <body> section.

The syntax of script tag is:
<body>
<script language="JavaScript" type="text/JavaScript">
..................
..................
<//JavaScript code
</script>
</body>

Leave a Reply