cancelBubble Property

DHTML, HTML, & CSS

cancelBubble Property


Sets or retrieves whether the current event should bubble up the hierarchy of event handlers.

Syntax

HTMLN/A
Scriptingevent.cancelBubble [ = bCancel ]

Possible Values

bCancel Boolean that specifies one of the following values:
falseBubbling is enabled, allowing the next event handler in the hierarchy to receive the event.
trueBubbling is disabled for this event, preventing the next event handler in the hierarchy from receiving the event.

The property is read/write with a default value of false.

Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see dynamic propertiesInternet Link.

Remarks

Using this property to cancel bubbling for an event does not affect subsequent events.

Example

This example cancels bubbling of the onclick event if it occurs in the IMG object when the user presses the SHIFT key. This prevents the event from bubbling up to the onclick event handler for the document.

Sample Code

<SCRIPT LANGUAGE="JScript">
function checkCancel()
{
    if (window.event.shiftKey)
        window.event.cancelBubble = true;
}
function showSrc()
{
    if (window.event.srcElement.tagName == "IMG")
        alert(window.event.srcElement.src);
}
</SCRIPT>

<BODY onclick="showSrc()">
<IMG onclick="checkCancel()" SRC="sample.gif">

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
HTML N/A
Scripting event

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.