Events are a feature of HTML documents (present in other programming languages too) that allow authors to add interactivity between the website and it’s visitors, by executing client-side programs when the visitor (or other program) performs an action. For example, the author can make a paragraph change the color of its text when the user puts the mouse pointer over it.
As well as attributes, events can be easily defined in an element’s start tag, with the same format:
<tag_name event_name="code">
Window Events
Consider the following code for window events.
Attribute
|
Value
|
Description
|
---|---|---|
onload() | script | Script to run when document loads |
Form Element Events
Attribute
|
Value
|
Description
|
---|---|---|
onchange | script | Script to be run when the element changes |
onsubmit | script | Script to be run when the form is submitted |
onreset | script | Script to be run when the form is reset |
onselect | script | Script to be run when the element is selected |
onblur | script | Script to be run when the element loses focus |
onfocus | script | Script to be run when the element gets focus |
Keyboard Events
Attribute
|
Value
|
Description
|
---|---|---|
onkeydown | script | Script to be run when key is presses |
onkeypress | script | Script to be run when key is presses and relesed |
onkeyup | script | Script to be run when key is relesed |
Mouse Events
Attribute
|
Value
|
Description
|
---|---|---|
onclick | script | What to do on a mouse click |
ondblclick | script | What to do on a mouse double-click |
onmousedown | script | What to do when mouse button is pressed |
onmousemove | script | What to do when mouse pointer moves |
onmouseout | script | What to do when mouse pointer moves out of an element |
onmouseover | script | What to do when mouse pointer moves over an element |
onmouseup | script | What to do when mouse button is released |