Hi James, Glad to help. One note:
> ...I hadn't realised that you could > assign the 'click' to the holding div and it would be applied to the > elements below it. Well, it's not really that it's *applied* to the elements below it. It's just that when an event is fired on an element (e.g., it's clicked or what-have-you), it fires on that element, and then its parent, and then *its* parent, etc., unless it's stopped. (You stop it from doing that by calling stopPropagation on the event instance, or calling Prototype's Event.stop() method -- which will also prevent the browser's default action taking place.) More on the W3C site.[1] And yeah, hugely useful thing to know... :-) [1] http://www.w3.org/TR/DOM-Level-2-Events/events.html -- T.J. Crowder tj / crowder software / com On Nov 6, 2:57 pm, "James Hoddinott" <[EMAIL PROTECTED]> wrote: > 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 [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
