asp.net.ph

Skip Navigation Links

cancelBubble Property

event Properties   DHTML Events


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

Syntax

HTML N/A
Script event.cancelBubble [ = bCancel ]

Possible Values

false Enables bubbling.
true Cancels bubbling for this event, preventing the next event handler in the hierarchy from receiving the event.

This property returns or accepts only a boolean value, meaning true if set, and false if not. The property is read/write with a default value of false.

Remarks

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

Example

The following document fragment cancels bubbling of the onclick event if it occurs in the IMG object when the SHIFT key is down. 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">
Applies To

event


Need a break ?
Suggested Reading

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph.

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