ondetach Event

MS Office DHTML, HTML & CSS

ondetach Event


Fires before the behavior is detached from the element.

Syntax

<PUBLIC:ATTACH
    EVENT = ondetach
    ONEVENT = sEventHandler
    FOR = element
    ID = sID
/>

Attributes

EVENT
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.
FOR
Optional. String that specifies one of the following values to identify the source of the event.
document Refers to the document object.
element Default. Refers to the element to which the behavior is attached.
window Refers to the window object.
ONEVENT
Required. String that specifies an inline script or a direct invocation of the event handler function.
ID
Optional. String that uniquely identifies the ATTACH element within the component. This attribute is analogous to the ID attribute in DHTML.

Remarks

A behavior can detach from an element if one of the following occurs:

  • The containing page is closed.
  • The behavior is removed from the page using the removeBehavior method.
  • The behavior property of the element is set to null, or reset to point to another behavior.
  • The className property of the element is set to null, or reset to some other class other than the one defined for the behavior.

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

Note 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 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.

Example

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

Sample Code

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

<SCRIPT LANGUAGE="JScript">
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 = "";
   }
}
</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

See Also

dhtml behaviorsInternet Link, implementing dhtml behaviors in scriptInternet Link

Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.