The event is not passed down to the underlying event but rather it bubbles up through the dom tree from the event where the event was triggered.
http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow-bubbling An example is probably easier to digest. This code has click handlers at body, td and div elements. Some the .stopTheEventBubbling elements will stop the event. Ian ---- <html> <head> <script src="http://code.jquery.com/jquery-latest.pack.js"></script> <script> $(document).ready(function(){ function setupHandler() { var tag = this.toString(); $(tag).click(function(event) { $('#log').append('event for ' + event.target.tagName + ' caught @ ' + this.tagName + ' - ' + event.timeStamp + '<br/>'); if ($(this).is(".stopTheEventBubbling")) { $(this).css("background", "#c44"); var that = this; setTimeout(function() { $(that).css("background", "#fff"); }, 2000); //return false; // or event.stopPropagation(); } }); } $(['body','td','div']).each( setupHandler ); }); </script> </head> <body> <table border=1> <tr> <td> <div>I bubble all the way.</div> <div class="stopTheEventBubbling">Only the div catches me.</div> </td> <td class="stopTheEventBubbling"> <div>The TD stops my bubbling.</div> </td> </tr> </table> <div id="log"></div> </body> </html> On 4/26/07, Stefan Kilp [sk-software] <[EMAIL PROTECTED]> wrote:
> or event.stopPropagation() is there a way to make this the default behavior. at the moment i don't see any example where is would make sence that the click event is passed to the underliing element. i think it is a commen behavior in most gui's (win, mac, ...) the only the first element in the z-order receives the event (if it has been registered). the problem is that i have data in rows and at the and of each row there are some 'action icons' (edit, delete, ...) now to select a datarow i bind click event to the surounding row element (div or tr). when i now click on one of the action icons, my select event is triggered, which in this case is not intended. any idea to solve this problem? thanks stefan > > ----- Original Message ---- > From: (J)(a)(k)(e) <[EMAIL PROTECTED]> > To: jquery-en@googlegroups.com > Sent: Wednesday, April 25, 2007 2:00:50 PM > Subject: [jQuery] Re: click event and z-order > > I believe your answer is false. > > if you return false at the end of the click code, no other element will be bothered with the click event. > > On 4/25/07, > Stefan Kilp [sk-software] <[EMAIL PROTECTED]> wrote: > > hi, > > if have two elements (a image in a table) which have a click event registered (on <img> and > <tr> element). if i click on the img in the table both click events are executed. i would expect > > that only the first element in the z-order gets the click event. > > it there something i missed, how can i change the behavior? > > thanks > stefan > -- > Stefan Kilp > SK-Software, Entwicklung & Beratung > > > email: [EMAIL PROTECTED] > > fon : +49 6151 93344-0 > fax : +49 6151 93344-20 > Herta-Mansbacher-Str. 98 > 64289 Darmstadt, Germany. > ----------------------------------------------------- > > > > > > > -- > (J)(a)(k)(e) - > > > > -- Stefan Kilp SK-Software, Entwicklung & Beratung email: [EMAIL PROTECTED] fon : +49 6151 93344-0 fax : +49 6151 93344-20 Herta-Mansbacher-Str. 98 64289 Darmstadt, Germany. -----------------------------------------------------