JAVASCRIPT

 Home  Computers & Internet  Web Programming JAVASCRIPT
What is Javascript?
Javascript Placement
Syntax
Reserved Words
Variables
Data Types
Escaping Characters
Concatenation
Arithmetic Operators
Assignment Operators
Comparison Operators
Boolean Operators
Conditional Operator
If Statements
Else If Statements
If Else Statements
Switch Statements
While Loops
For Loops
Do While Loops
Break Statement
Continue Statement
prompt()
alert()
Date()
Event Handlers
String Object Methods
Math Object Methods
Window Object Methods

WHERE TO PLACE JAVASCRIPT CODE ON YOUR WEBPAGES

Javascript can be placed between the <head> and </head> tags of your html page or between the <body> and </body> tags.

Script between the head tags require an event to trigger whereas script in the body triggers when the page loads. Since the head section loads before the body section, it is preferred that javascript that requires a trigger to initiate be placed between the <head> and </head> tags as this will ensure that the javascript code is ready when the page loads.

Option 1:

<html>
<head>
<script type="text/javascript">

your javascript code here

</script>
</head>
<body>

Your page content here.

</body>
</html>

Option 2:

Javascript that is placed in the body triggers when the page loads.

<html>
<head>

</head>
<body>

<script type="text/javascript">

your javascript code here

</script>

</body>
</html>

Option 3:

Your javascript code can also be placed in a separate js file and referenced as such:

<html>
<head>
<script type="text/javascript" src="somepage.js"></script>
</head>
<body>

Your page content here.

</body>
</html>

This code will then function as if it were in the head section (Option 1) as in the first example.



Home | Privacy Policy | Terms Of Use | Contact Us