Pages

JavaScript Function in head Tag

JavaScript Function in <head>

In this example, a JavaScript function is placed in the <head> section of an HTML page.
The function is called when a button is clicked:

 

 

 

 

Example

<!DOCTYPE html>
<html>
<head> <script>
function myFunction()
{
document.getElementById("demo").innerHTML="My First JavaScript Function";
}
</script>

</head>

<body>
<h1>My Web Page</h1>
<p id="demo">A Paragraph</p>
<button type="button" onclick="myFunction()">Try it</button>
</body>
</html>

No comments:

Flag Counter
| Copyright © 2013 Remote Tutor