Javascript banner image.

In the Hello World! Javascript primer our Javascript ran as soon as the script loaded in the browser. Javascript is event-driven: scripts run when a specific HTML event occurs in an HTML document. In the Hello World! example, the event is the loading of the page. In this example, we will use the onclick event.

<html>
<head>
	<title>Javascript's onclick event</title>
</head>
<body>

<h1>The onclick Event</h1>
<img src="sicon_mini.gif" id="pageLogo" alt="The stylus logo." onclick="myFunction()" />

<script>
function myFunction() {
	alert("You clicked, Lord Master?");
}
</script>

</body>
</html>

See the Pen Javascript’s onclick() event by David Fox (@foxbeefly) on CodePen.

By MisterFoxOnline

CAT Educator

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.