HTML events can trigger actions in the browser, like starting a JavaScript when a user clicks on an element.
Examples
onclick
Turn on the light! How to change an image when the user clicks it.
onmousedown & onmouseup
This time the light is on only when the user holds down the mouse button.
onload
Displays an alert box when the page has finished loading.
Event handlers
An event handler allows you to execute code when an event occurs.
Events are generated by the browser when the user clicks an element, when the page loads, when a form is submitted, etc.
Example
A header changes when the user clicks it:
Code:
<h1 onclick="this.innerHTML='Ooops!'">Click on this text</h1>
You can also add a script in the head section of the page and then call the function from the event handler:
Code:
<html>
<head>
<script type="text/javascript">
function changetext(id)
{
id.innerHTML="Ooops!";
}
</script>
</head>
<body>
<h1 onclick="changetext(this)">Click on this text</h1>
</body>
</html>
HTML 4.0 Event Handlers
