Event handlers

by Haig. Average Reading Time: less than a minute.

An event handler can be considered a trigger that executes code when something happens, in the ‘event’ of a click or move your mouse over a link, submit a form etc.


onClick handlers execute something only when users click on buttons, links, etc. Let’s see an example:

			function specialsauce() {
				alert("Thank you!")
			<input type="button" value="Click here" onclick="specialsauce()">

The function specialsauce() is invoked when the user clicks the button. Note: Event handlers are not added inside the <script> tags, but rather, inside the html tags.


The onload event handler is used to call the execution of JavaScript after loading:

	<body onload="ss()">
		<frameset onload="ss()">
		<img src="whatever.gif" onload="ss()">

No comments on ‘Event handlers’

Leave a Reply