2008/11/6 T.J. Crowder <[EMAIL PROTECTED]>:
> So you might consider event delegation instead.  Put your click
> handler on the dticketlist element, and you don't have to do
> *anything* to hook up the individual ticket items:  Events bubble up
> the DOM tree, and so a click on the ticket will also show up as a
> click on the dticketlist div.  In an event handler, Prototype ensures
> that 'this' is set to the element you set the handler on, but the
> Event.element() very handily references the element that was clicked.

We have success! Hurrah \o/

This is actually really interesting, I hadn't realised that you could
assign the 'click' to the holding div and it would be applied to the
elements below it.

> With the click handler on dticketlist, your PeriodicalUpdater gets
> simpler:
> new Ajax.PeriodicalUpdater('dticketlist','data/
> fetchliveticketview.php',{
>    frequency:300,
>    decay:2
> });
> ...and your handler code looks something like this:
> function ticketClicked(evt)
> {
>    var elm;
>    var id;
>    elm = evt.element();
>    if (elm && elm.hasClassName('clickinc'))
>    {
>        // It's one of our list items
>        id = elm.id || '(no id)';
>        $('dmain').update('Ticket #' + id + ' clicked');
>    }
> }

Thanks for this T.J. It's quite fundamental to a number of parts of
what I'm working on so I'm pleased to have found a solution and learnt
some new tips and tricks along the way.

Thanks also to Alex for his help and perseverance, and to Walter too.

James Hoddinott

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 

Reply via email to