cancelBubble Property
cancelBubble Property

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

Syntax

[ bCancel = ] object.cancelBubble

Possible Values

bCancelBoolean that specifies or receives one of the following values.
false
Default. Bubbling is enabled, allowing the next event handler in the hierarchy to receive the event.
true
Bubbling is disabled for this event, preventing the next event handler in the hierarchy from receiving the event.

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

DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are not supported in IE8 mode. For more information, see About Dynamic Properties.

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.

<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">

Standards Information

There is no public standard that applies to this property.

Applies To

event, Event Constructor
Community Content

limitation - Alt
Added by:Mr. Raymond Kenneth Petry
Note that Alt-Enter/Alt-arrow cannot be cancelBubble'd to override their default Windows/document action... (but there are also some deeper settings).
© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View