Event Handler in Javascript
This program is about event handler in javascript.
What is an event handler?
An event handler executes a segment of a code based on certain events occurring within the application, such as onLoad, onClick.Handlers are small pieces of code (function) that know what to do when an event occurs.
Screenshot:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Guess the Image</title>
<style>
body {margin: 20px; }
img { margin: 20px; }
</style>
<script>
window.onload= init;
function init() {
var image = document.getElementById("nature");
image.onclick = showAnswer;
};
function showAnswer() {
var image = document.getElementById("nature");
image.src = "boats.jpg"
}
function timehandler() {
alert("Hey!! What are you waiting for? Click on the image")
}
setTimeout(timehandler, 5000);
</script>
</head>
<body>
<img id="boats" src="boatsblur.jpg">
</body>
</html>
Leave a comment.
Comments
Post a Comment