Click to return to home page
Richard Lowe Jr Home

Events

Description Attributes Examples Tips

Description:

Events are things that can occur within an element. These include mouse clicks and movement, document loading and anything else that can happen in the area bounded by a tag. An event is valid on most tags, and they are specified in this reference wherever they may be used.

Attributes:

ondblclick=JavaScript

Specifies JavaScript code to be executed when a double-click is detected anywhere in the element.

onblur=JavaScript

Specifies JavaScript code to be executed when the window of the document loses focus.

onfocus=JavaScript

Specifies JavaScript code to be executed when the window of the document gains focus.

onkeydown=JavaScript

JavaScript to be executed when a key is pressed in anywhere in the element.

onkeyup=JavaScript

JavaScript to be executed when a key is pressed and then released in anywhere in the element.

onmousedown=JavaScript

If a mouse button is pushed down anywhere in the element, then this JavaScript is executed.

onmousemove=JavaScript

If the mouse moves anywhere in the element, then this JavaScript is executed.

onmouseout=JavaScript

If the mouse moves out of the element, then this JavaScript is executed.

onmouseover=JavaScript

If the mouse moves over an element, then this JavaScript is executed.

onload=JavaScript

Specifies JavaScript code to be executed when the page is loaded. 

onunload=JavaScript

Specifies JavaScript code to be executed when the page is unloaded.

Examples:

<A HREF="/member/privacy.html" onMouseOver="self.status='Privacy Policy';
return true;" onMouseOut="self.status='';return true;">Privacy Policy</A>

This code creates a link with the label "Privacy Policy". When the mouse is moved to any of the text "Privacy Policy" (onMouseOver), the variable "self.status" is set to "Privacy Policy" (this sets the value of the status line on the lower left of the browser window). When the mouse moves away from the text the status line is erased.

Tips:

  1. Remember events are newer elements in HTML and are not supported by older browsers.

  2. In addition, if someone disables JavaScript then the JavaScript code will not be executed.


Unless otherwise noted, all photos and text is Copyright © Richard G Lowe, Jr.