JavaScript in (head)
The example below calls a function when a button is clicked:
<html>
<head>
<script type="text/javascript">
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>
<h1>My First Web Page</h1>
<p id="demo"></p>
<button type="button" onclick="displayDate()">Display Date</button>
</body>
</html>
Scripts in <head> and <body>
You can place an unlimited number of scripts in your document, and you can have scripts in both the body and the head section at the same time.
It is a common practice to put all functions in the head section, or at the bottom of the page. This way they are all in one place and do not interfere with page content.
JavaScript in (head)
.
Categories
- ASP (4)
- HTML (4)
- JavaScript (4)
- PHP (4)
- Visual Basic (4)
- XML (5)
Popular Posts
-
The following console program is the Visual Basic version of the traditional "Hello, World!" program, which displays the string ...
-
change button color in visual basic Public Class Form1 Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As System.Windows...
-
XML Attribute Values Must be Quoted XML elements can have attributes in name/value pairs just like in HTML. In XML, the attribute values...
-
A message box when page opens (Javascript Code) You can bring a message box or a alert a window which tell something to user at the first ...