EN
이 콘텐츠는 한국어로 제공되지 않아 영어 버전으로 표시됩니다.

cancelBubble property

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

Syntax

JavaScript

p = object.cancelBubble

 

Property values

Type: Boolean

false (false)

Default. Bubbling is enabled, allowing the next event handler in the hierarchy to receive the event.

true (true)

Bubbling is disabled for this event, preventing the next event handler in the hierarchy from receiving the event.

Remarks

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

Examples

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 type="text/javascript">
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.png">

See also

event

 

 

표시:
© 2014 Microsoft