Microsoft HomeproductssearchsupportshopWrite Us   Microsoft Home
Magazine
 |  Community
 |  Workshop
 |  Tools & Samples
 |  Training
 |  Site Info

Workshop  |  DHTML, HTML & CSS

attachEvent Method


This document describes technologies available in the Internet Explorer 5 Beta. While we encourage you to evaluate these features and to send us your feedback, please note that these features are subject to change.

Binds the specified function to an event so that the function gets called whenever the event fires on the object.

Syntax

bSuccess = object.attachEvent(sEvent, fpNotify)

Parameters

sEvent Required. Specifies the name of the event.
fpNotify Required. Specifies the function to be called whenever sEvent fires.

Return Value

Boolean. Returns TRUE if the function was bound successfully to the event, or FALSE otherwise.

Remarks

When sEvent fires on the object, the object's sEvent handler is called first, before the specified function, fpNotify. If multiple functions are attached to the same event on the same object, the functions will be called in a random order, immediately after the object's event handler is called.

This method provides a means for a behavior to listen in on events that occur on the containing page. It is not limited, however, to behaviors. A function defined on a page can be attached to events fired on the same page as well.

Example

The following example implements a mouseover highlight effect using a behavior. The sample demonstrates two ways of attaching to events: using the ATTACH element defined for HTML Components (HTC), and using the attachEvent method. The ATTACH element is simply a declarative form of the attachEvent method.

Sample Code

<PROPERTY NAME="hiliteColor" />
<ATTACH EVENT=onmouseover HANDLER=event_onmouseover />
<ATTACH EVENT=onmouseout  HANDLER=event_onmouseout  />

<SCRIPT LANGUAGE="JScript">
var normalColor;

window.attachEvent ("onload", event_onload);

function event_onload()
{
// initialize the properties
  if (hiliteColor == null)
     hiliteColor = "red";
}

function event_onmouseover()
{
  normalColor = style.color;
  style.color = hiliteColor;
}

function event_onmouseout()
{
  style.color = normalColor;
}
</SCRIPT>

This feature requires Microsoft® Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

See Also

detachEvent, Scriptlets Overview


Does this content meet your programming needs? Write us!

Back to topBack to top

© 1998 Microsoft Corporation. All rights reserved. Terms of use.

 

Magazine Home
Ask Jane
DHTML Dude
Extreme XML
For Starters
More or Hess
Servin' It Up
Site Lights
Web Men Talking
Member Community Home
Benefits: Freebies & Discounts
Benefits: Promote Your Site
Benefits: Connect with Your Peers
Benefits at a Glance
Online Special-Interest Groups
Your Membership
SBN Stores
Join Now
Workshop Home
Essentials
Content & Component Delivery
Component Development
Data Access & Databases
Design
DHTML, HTML & CSS
Extensible Markup Language (XML)
Languages & Development Tools
Messaging & Collaboration
Networking, Protocols & Data Formats
Reusing Browser Technology
Security & Cryptography
Server Technologies
Streaming & Interactive Media
Web Content Management
Workshop Index
Tools & Samples Home
Tools
Samples, Headers, Libs
Images
Sounds
Style Sheets
Web Fonts
Training Home
SBN Live Seminars
SBN Live Chats
Courses
Peer Support
CD-ROM Training
Books & Training Kits
Certification
SBN Home
New to SBN?
What's New on SBN
Site Map
Site Search
Glossary
Write Us
About This Site