Menu

JAVASCRIPT TUTORIALS - Javascript - Placement

Javascript - Placement

ADVERTISEMENTS

JavaScript in <head>...</head> section:


<html>
<head>
<script type="text/javascript">
<!--
function sayHello() {
   alert("Hello World")
}
//-->
</script>
</head>
<body>
<input type="button" onclick="sayHello()" value="Say Hello" />
</body>
</html>

ADVERTISEMENTS



ADVERTISEMENTS

JavaScript in <body>...</body> section:


<html>
<head>
</head>
<body>
<script type="text/javascript">
<!--
document.write("Hello World")
//-->
</script>
<p>This is web page body </p>
</body>
</html>



Advertisements
This is web page body

JavaScript in <body> and <head> sections:


<html>
<head>
<script type="text/javascript">
<!--
function sayHello() {
   alert("Hello World")
}
//-->
</script>
</head>
<body>
<script type="text/javascript">
<!--
document.write("Hello World")
//-->
</script>
<input type="button" onclick="sayHello()" value="Say Hello" />
</body>
</html>



Advertisements

JavaScript in External File :


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


function sayHello() {
   alert("Hello World")
}