Questions tagged [event-bubbling]

The concept of parent elements handling events that are propagated by a child element

In event bubbling, an event is propagated through the ancestors of the element that initially receives the event.

For example:

<div id='main' onclick='mainCode();'>
<div id='kid1' onclick='myVar=1;'></div>
<div id='kid2' onclick='myVar=2;'></div>
</div>

The click event bubbles, and so is propagated to the main <div> element after being handled by a kid <div> element.

This can make code simpler to understand, for example if mainCode() has access to the myVar variable, determining which kid sent the message is easy.

References

567 questions
0
votes
3 answers

find out instantiating object in the constructor of a class

How can i get hold of the instantiating object from a constructor in java? I want to store reference to the parent object for some GUI classes to simulate event bubbling - calling parents handlers - but i dont wanna change all the existing code.
Andreas
  • 545
  • 1
  • 4
  • 16
0
votes
2 answers

jQuery prevent all event bubbling

I'm using jQuery with it's widget factory and using custom events to handle events in my application. This means that all my event binding looks a lot like: //...in the widget factory…
Danack
  • 24,939
  • 16
  • 90
  • 122
0
votes
1 answer

Use same function as "standard" one and as an event handler

I have a function function foo(event, var1) { // do something... } I am using this function in some event bubbling, but I also need to use as a normal function that's called by me from my code. Event parameter is used only with event bubbling.…
Robotronx
  • 1,728
  • 2
  • 21
  • 43
0
votes
6 answers

Delay execution of event up the 'event bubble order' until ajax call completes

EDIT: in response to comments about executing click event programaticaly on the anchor element, or using, window.open- I can't use these because of the popup blocker. I must allow the original mouseclick event on the anchor by the user to complete…
CodeToad
  • 4,656
  • 6
  • 41
  • 53
0
votes
1 answer

Catching clicks on link (event bubbling)

I'm fairly new to raw JavaScript (used to working with jQuery). I need to catch clicks on a few links, prevent the default action and then do something based on the link href. Some links are straight up Lorem, but others…
Bram
  • 1,112
  • 1
  • 9
  • 23
0
votes
2 answers

Listen for changes against an Object In an array without nesting event listeners

(disclaimer: this question is much simpler than the title suggests!) I have a re-occuring problem in my program architecture with listening to changes against a model. I have set-up some collections (much like in Backbone.js) which are just…
Jon Wells
  • 4,191
  • 9
  • 40
  • 69
0
votes
2 answers

preventDefault() for keypress cancels change event

In the code snippet below, I'm trying to prevent the user from entering new lines into a