event Properties DHTML Events
Sets or retrieves whether the current event should bubble up the hierarchy of event handlers.
HTML |
N/A |
Script |
event.cancelBubble [ = bCancel ] |
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.
Using this property to cancel bubbling for an event does not affect subsequent events.
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">
event