DOM Events - Event Flow

Event Flow

Consider the situation when there are 2 elements nested together. Both have event handlers registered on the same event type, say "click". When the user clicks on the inner element, there are two possible ways to handle it:

  • Trigger the elements from outer to inner (event capturing). This model is implemented in Netscape Navigator.
  • Trigger the elements from inner to outer (event bubbling). This model is implemented in Internet Explorer and other browsers.

W3C takes a middle position in this struggle. Events are first captured until it reaches the target element, and then bubbled up. During the event flow, an event can be responded to at any element in the path (an observer) in either phase by causing an action, and/or by stopping the event (with method event.stopPropagation for W3C-conforming browsers and command event.cancelBubble = true for Internet Explorer), and/or by cancelling the default action for the event.

Read more about this topic:  DOM Events

Famous quotes containing the words event and/or flow:

    When we awoke, we found a heavy dew on our blankets. I lay awake very early, and listened to the clear, shrill ah, te te, te te, te of the white-throated sparrow, repeated at short intervals, without the least variation, for half an hour, as if it could not enough express its happiness. Whether my companions heard it or not, I know not, but it was a kind of matins to me, and the event of the forenoon.
    Henry David Thoreau (1817–1862)

    Parents ought, through their own behavior and the values by which they live, to provide direction for their children. But they need to rid themselves of the idea that there are surefire methods which, when well applied, will produce certain predictable results. Whatever we do with and for our children ought to flow from our understanding of and our feelings for the particular situation and the relation we wish to exist between us and our child.
    Bruno Bettelheim (20th century)