Try this:

$("#elementA").unbind("click").click( function () {
   $("#elementB").show();
});

$("#elementB").unbind("click").click( function () {
   $(this).hide();
});

The problem is not event "bubbling" per se.  It's more a case of you are 
adding element B, then applying event handlers.  At a later time, you 
again add element B and apply event handlers again.  You now have two 
event handers assigned.

Using the sample above, you are explicitly saying to unbind the "click" 
event handler - so that there is NO handler for the click event.  Then 
we apply a click handler afterwards.  This approach ensures only one 
handler is fired.

Of course, this may not be quite what you want in all cases, but I trust 
  you to know your needs.. :)  Also, a jQuery guru may correct me and 
offer an easier method....

HTH

Shawn

julio wrote:
> Hi,
> 
> I have this situation:
> 
> When I click on an element (A), a new element (B) of same type is
> overlayed to A on foreground.
> When I click on B, B disappares and remain A on foreground. When I re-
> click on A 2 elements B are overlayed instead of 1.
> 
> I guess this is a problem of event-bubbling, and so instead of use
> "bind" to catch click event of mouse, I use "one" for A and B.
> Obviously "one" permits only one click for an element, and so I cannot
> click a second time on A or B. How can I reset "one-condition"
> everytime on element is on foreground? Or this is not event-bubbling
> problem and solution is another?
> 
> Thanks,
> Julio

Reply via email to