Posted By

noah on 06/06/07


DOM events eventhandlers ppk interaction bubbing quirksmode bubble propagation

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Stop event propagation (stop an event from bubbling up)

 / Published in: JavaScript

This is useful if I have an element that is inside a container, and I want to the element's event handler to fire without triggering the container's event handler. Then I would wrap the element's event handler function with this code.

See "PPK On JavaScript," pp. 315 and 323.

  1. function doSomething (e) {
  2. var event = e || window.event;
  4. [body of event handler function goes here]
  6. if (event.stopPropagation) {
  7. event.stopPropagation();
  8. } else {
  9. event.cancelBubble = true;
  10. }
  11. }

Report this snippet  

You need to login to post a comment.