Applying
JavaScript (Internal and External)
JavaScript
can be added to your HTML file in two ways:
· InternalJavaScript
· ExternalJavaScript
Internal JavaScript:
We
can add JS code directly to our HTML file by writing the code inside the
<script>& </script>. The<script>tag can either be placed
inside the<head>orthe<body>tag according to the requirement.
Example:
It
is the basic example of using JavaScript code inside of HTML code, that script
enclosing section can be placed in the body or head of the HTMLdocument.
<!DOCTYPEhtml>
<htmllang="en">
<head>
<title>
BasicExampletoDescribeJavaScript
</title>
</head>
<script
src="main.js"></script>
</head>
<body>
</body>
</html>
OUTPUT:
The
output will display on console.
Welcome
to JavaScript
(OR)
b) JavaScript
/*
JavaScript code can be embedded inside
head
section or body section */
console.log("Welcome
to JavaScript");
//
JavaScript file name: main.js
OUTPUT:
The
output will display on console.
Welcome
to JavaScript
PROGRAM:
AIM:
Creating and Using external JavaScript file in HTML document
// JavaScript Document
a=prompt("Enter your Name:");
document.write("<font
face='britanic bold' color='green'
size=14>Hai..."+a+"</font>");
<html>
//accessing external
script file from HTML document
<head><title>
Using external Java Script</title></head>
<body>
<script
language="JavaScript" src="wish.js"
type="Text/JavaScript"></script>
</body>
</html>