Embedding Java Script in HTML
Previous Page | Home Page | Next Page |
---|
There are two ways to use of JavaScript in HTML. One way, you can store your script in a separate simple text file and include it in your HTML document, other way, you can directly write your script inside HTML document. The basic structure of an HTML file with JavaScript is as follows (JavaScript is indicated in bold):
<HTML>
<HEAD>
<TITLE>Page title goes here</TITLE>
<SCRIPT Language="JavaScript">
Your JavaScript code goes here
</SCRIPT>
</HEAD>
<BODY>
Document Text goes here
<SCRIPT Language="JavaScript">
Your JavaScript code goes here too
</nowiki>
</SCRIPT>
Document text here too
</BODY>
</HTML>
A sample HTML document embedding a JavaScript shown in
below:
<HTML>
<HEAD>
<TITLE>JavaScript Example </TITLE>
</HEAD>
<BODY>
This Document shows the use of JavaScript in HTML.
<BR>
<SCRIPT language="JavaScript">
document.write("Welcome to the world of JavaScript!")
</SCRIPT>
</BODY>
</HTML>
‘Document’ – Predefined Java Script Object refer to the HTMLdocument(web page).
‘write’ – It is a predefined method of document object that is usedto write text to the HTML document.
The output of the Example shown in below:
Previous Page | Home Page | Next Page |
---|