asp.net.ph

Skip Navigation Links

attachEvent Method

DHTML Methods


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


See Also

detachEvent



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note