Thanks Mike,

I guess what I'm wrestling with, is what advantages the plugins offer
(I'm not that adept at javascript, but I'm hoping to 'sell' the
concept to others who are more adept at it). We have some big data
tables with lots of clicks, sometimes expanding rows, sometimes hovers
or clueTips, and sometimes the clicks will trigger a jqModal-
controlled window (hence my interest in how to work with jqModal in
this event delegation scenario).

I agree - the concept is brilliantly simple - and maybe that's what
makes me nervous :-)





On Aug 19, 2:10 pm, "Michael Geary" <[EMAIL PROTECTED]> wrote:
> If you really want to understand event delegation, you may want to just look
> at the raw code to implement it instead of a plugin. That way you can see
> how it actually works.
>
> It's really quite simple: You attach an event handler to some common parent
> element, and then check event.target on the incoming events to decide what
> to do with them.
>
> Here's an example. Suppose you have a thousand <a> elements on your page,
> and you want to intercept all clicks on them. You also want to intercept
> clicks on any other elements that have a "clickme" class and do something
> different with them - and you have a thousand of these too.
>
> You could do that easily with this jQuery code:
>
>     $(function() {
>         $('a').click( function() {
>             alert( 'Clicked A' );
>             return false;  // suppress standard click behavior
>         });
>         $('.clickme').click( function() {
>             alert( 'Clicked CLICKME' );
>         });
>     });
>
> That's short and simple... But behind the scenes it will install two
> thousand event handlers!
>
> Instead of that, you can do this:
>
>     $(function() {
>         $('body').click( function( event ) {
>             var $target = $(event.target);
>             if( $target.is('a') ) {
>                 alert( 'Clicked A' );
>                 return false;  // suppress standard click behavior
>             }
>             if( $target.is('.clickme') ) {
>                 alert( 'Clicked CLICKME' );
>             }
>         });
>     });
>
> Now you're only installing *one* event handler instead of two thousand.
>
> That's really all there is to event delegation. You don't have to use
> $target.is(...) - you can write any code you wish to distinguish among the
> different elements. The DOM element that triggered the event is in
> event.target.
>
> The event delegation plugins make it even simpler to write this code, of
> course.
>
> -Mike
>
> > I'm trying to get my head around the concept of event
> > delegation, and have been reading about jquery.listen and
> > jquery.delegate and LowPro for jQuery... and I'm a little
> > confused as to the strengths and weaknesses, or scope,  of
> > each approach.
>
> > Can anyone offer some wise words on this topic?
>
> > How does one integrate a plugin like jqModal with one of
> > these event delegation plugins?
>
> > any thoughts are appreciated!

Reply via email to