HOME

DHTML Tutorial
DHTML HOME
DHTML Intro
DHTML CSS
DHTML DOM
DHTML Events

DHTML Examples
DHTML Examples

DHTML DOM
DOM window
DOM navigator
DOM event
DOM collection
DOM document
DOM form
DOM input
DOM select
DOM option
DOM textarea
DOM table
DOM tablerow
DOM tablecell
DOM anchor
DOM image
DOM frameset
DOM frame
DOM iframe

DOM Examples
DOM Examples
Award Winning Web Host Full Services Including Ecommerce
Please visit our sponsors !

DHTML Event Handlers

previous next

With an event handler you can do something with an element when an event occurs.


Examples

Note: Most of the DHTML examples require IE 4.0 or higher.

onmouseover & onmouseout
How to change the color of an element when the cursor moves over and out of an element.

onclick
Turn on the light! How you can change an image when you click on it, and back to the original image when you click on it again.

onmousedown & onmouseup
This time the light is on only when you hold the mouse button down.

onload
Displays an alert box when the page has finished loading.


Event handlers

With an event handler you can do something with an element when an event occurs: when the user clicks an element, when the page loads, when a form is submitted, etc.

<h1 onclick="style.color='red'">Click on this text</h1>

The example above defines a header that turns red when a user clicks on it.

You can also add a script in the head section of the page and then call the function from the event handler:

<html>
<head>
<script type="text/javascript">
function changecolor()
{
header.style.color="red"
}
</script>
</head>
<body>
<h1 id="header" onclick="changecolor()">
Click on this text</h1>
</body>
</html>


HTML 4.0 Event Handlers

Event When it occurs
onabort User aborted page loading
onblur User left an object
onchange User changed the value of an object
onclick User clicked on an object
ondblclick User double clicked an object
onfocus User made an object active
onkeydown When a keyboard key is on its way down
onkeypress When a keyboard key is pressed
onkeyup When a keyboard key is released
onload Page finished loading
onmousedown User pressed a mouse-button
onmousemove Cursor moving on an object
onmouseover Cursor moved over an object
onmouseout Cursor moved off an object
onmouseup User released a pressed mouse-button
onreset User resets a form
onselect User selected content on a page
onsubmit User submitted a form
onunload User left window


previous next

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Dogpile Alta Vista MSN Google Excite Lycos Yahoo Ask Jeeves


We Help You For Free. You Can Help Us!


W3Schools is for training only. We do not warrant its correctness or its fitness for use. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2002 by Refsnes Data. All Rights Reserved


Validate How we converted to XHTML Validate

IISProtect
Password Protect
Your Web Pages



Your own Web Site?

Read W3Schools
Hosting Tutorial



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search