On 6 syys, 15:50, Karl Swedberg <[EMAIL PROTECTED]> wrote:
> You should be able to do that using event.target. Try this:
>
> $('ul').one('click', function(event) {
>    if ( !$(event.target).is('a') ) {
>      // your code here
>    }
> });

This is normal bubbling and should be used more :)

But in this case I'm not that sure it would help. The events bound to
the actual a-element would still fire first, since normally bubbling
goes from bottom top top. I think this is pretty much the de facto
standard way of dealing with bubbling. The browsers pretty much
support also triggering event handlers in the capture phase (when
going from top to bottom before going back from bottom to top again)
if the event handlers are set to trigger at capture phase. As Karl R.
mentioned, though, there might be some buggy stuff in browsers
concerning this (it's not used that much).

You set the event handler to fire in the capture phase instead of the
normal bubbling phase by passing true as the third parameter to the
addEventListener-function.
More information, for example:
http://developer.mozilla.org/en/docs/DOM:element.addEventListener
http://my.opera.com/hallvors/blog/2006/10/12/2006-10-12-event-capture-explained

I dont think jQuery's norma bind-method gives you this functionality
directly, though, as it is generally not used at all, and there is
lots of advice floating against it's use. Usually you can achieve the
same functionality with other methods. The false-parameter for
addEventListener is hard coded in jQuery (line 1455 in jquery
1.1.4.js). You could of course tweak it here to support capturing
events also, or maybe there should be one more optional parameter that
we could pass to bind to enable this functionality (would not take
much work or space to implement).

You should be able to get the same functionality without those tweaks
anyway. Pretty hard to give advice though, since I have no clue on
what you're really trying to achieve :)

You could check for some flag, expando property, variable, metadata or
class when the inner elements are clicked and not fire their actions
if the ul fucntion has not yet fired, but instead let it bubble up
there.


Reply via email to