

ondetach Event

Fires before a behavior is detached from an element.


    EVENT = ondetach
    ONEVENT = sEventHandler
    FOR = element
    ID = sID


Required. String that specifies the name of a Dynamic HTML (DHTML) event, or any of the events specific to the HTML Component (HTC) that are listed in the HTC Reference.
Optional. String that specifies one of the following values to identify the source of the event.
Refers to the document object.
Default. Refers to the element to which the behavior is attached.
Refers to the window object.
Optional. String that uniquely identifies the PUBLIC:ATTACH element within the component. This attribute is analogous to the ID attribute in DHTML.
Required. String that specifies an inline script or a direct invocation of the event handler function.


The ondetach event allows the behavior to perform some cleanup just before it completely detaches from the element.

In cases where a behavior attaches to events on the containing page using the attachEvent method, this event gives the behavior the opportunity to call the detachEvent method to stop receiving notifications from the page. A behavior that attaches to events on the page using the PUBLIC:ATTACH element automatically stops receiving notifications when the behavior detaches from the element, and does not need to call the detachEvent method when the ondetach event fires.


This example uses the ondetach event to turn off the highlighting effect on a list of items initially attached to a highlighting behavior.

<PUBLIC:ATTACH EVENT="ondetach" ONEVENT="cleanup()" />

attachEvent ('onmouseover', Hilite);
attachEvent ('onmouseout', Restore);

function cleanup()
   detachEvent ('onmouseover', Hilite);
   detachEvent ('onmouseout', Restore);

function Hilite()
   if (event.srcElement == element)
     normalColor = style.color;  
     runtimeStyle.color  = "red";
     runtimeStyle.cursor = "hand";

function Restore()
   if (event.srcElement == element)
      runtimeStyle.color  = normalColor;
      runtimeStyle.cursor = "";

See Also

Community Additions

© 2014 Microsoft