HTML DOM - Events
functions. For example, we can use the onClick event of a button element to
indicate that a function will run when a user clicks on the button. We define
the events in the HTML tags.
Examples of events:
- A mouse click
- A web page or an image loading
- Mousing over a hot spot on the web page
- Selecting an input box in an HTML form
- Submitting an HTML form
- A keystroke
Note: Events are normally used in combination with functions, and the
function will not be executed before the event occurs!
For a complete reference of the events supported by the HTML DOM, see our
HTML DOM Event reference.
onload and onUnload
The onload and onUnload events are triggered when the user enters or leaves
The onload event is often used to check the visitor's browser type and
browser version, and load the proper version of the web page based on the
Both the onload and onUnload events are also often used to deal with cookies
that should be set when a user enters or leaves a page. For example, you could
have a popup asking for the user's name upon his first arrival to your page. The
name is then stored in a cookie. Next time the visitor arrives at your page, you
could have another popup saying something like: "Welcome John Doe!".
onFocus, onBlur and onChange
The onFocus, onBlur and onChange events are often used in combination with
validation of form fields.
Below is an example of how to use the onChange event. The checkEmail()
function will be called whenever the user changes the content of the field:
<input type="text" size="30"
onMouseOver and onMouseOut
onMouseOver and onMouseOut are often used to create "animated" buttons.
Below is an example of an onMouseOver event. An alert box appears when an
onMouseOver event is detected:
onmouseover="alert('An onMouseOver event');return false">
<img src="w3schools.gif" width="100" height="30">
The Altova MissionKit is a suite of intelligent XML tools, including:
XMLSpy® – industry-leading XML editor
- Support for all XML-based technologies
- Graphical editing views, powerful debuggers, code generation, & more
MapForce® – graphical data mapping tool
- Drag-and-drop data conversion with code generation
- Support for XML, DBs, EDI, Excel® 2007, text, Web services
StyleVision® – visual stylesheet designer
- Drag-and-drop stylesheet design for XML & databases
- Output to HTML, PDF, RTF, Word 2007, & more
Try before you buy with a free fully functional 30-day trial
Get Your Diploma!
W3Schools' Online Certification Program is the perfect solution for busy
professionals who need to balance work, family, and career building.
The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.
The XML Certificate is for developers who want to document their knowledge of XML, XML DOM and XSLT.
The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.
The PHP Certificate is for developers who want to document their knowledge of PHP and SQL (MySQL).