Hi, I need help with the following problem. <code> var xspanid = .. whatever ... Event.observe(xspanid, "click", this.deleteitem.bindAsEventListener(this, xspanid)); </code> the code above works (I''ve included two lines that I think are equivalent and both work the same, just . The problem I''m having is that deleteitem is only bound to the most recent span to which I attach this event, instead of to all of them. on the other hand, if I run a loop on all the spans together and attach the events within that loop, then they all work. But only want to attach an observer once, at the moment the span is created. The difference in the loop is that one is cycling through dom element, such as : <code> X = $$(''span.xspan''); // gets a collection of span elements I''m interested in X.each(function(item) { // Event.observe(item, "click", this.deleteitem.bindAsEventListener(item, item.id)); }.bind(this));\ </code> so "item" is not the same sort of thing as "xspanid" above. Thus, I tried it like this as well: <code> Event.observe($(xspanid), "click", this.deleteitem.bindAsEventListener(this, xspanid)); </code> with exactly the same results. Only that last span that gets passed through here gets an observer attached to it. I really don''t understand why it works just as well, to the extent that it does, with either an element id or the whole element as the first argument. But that''s another question. Thanks in advance for any help. Best ecb --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, This group is essentially closed to new posts. Use the new, better- named, hopefully-spam-free group for Prototype and script.aculo.us: http://groups.google.com/group/prototype-scriptaculous/ prototype-scriptaculous-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Hope this helps. -- T.J. Crowder tj / crowder software / com On Jul 23, 3:00 am, ecb <s...-fLhsMdZZi9zzJm9tdWFm49BPR1lH4CV8@public.gmane.org> wrote:> Hi, > > I need help with the following problem. > > <code> > var xspanid = .. whatever ... > Event.observe(xspanid, "click", > this.deleteitem.bindAsEventListener(this, xspanid)); > </code> > > the code above works (I''ve included two lines that I think are > equivalent and both work the same, just . The problem I''m having is > that deleteitem is only bound to the most recent span to which I > attach this event, instead of to all of them. > > on the other hand, if I run a loop on all the spans together and > attach the events within that loop, then they all work. But only want > to attach an observer once, at the moment the span is created. > > The difference in the loop is that one is cycling through dom element, > such as : > <code> > X = $$(''span.xspan''); // gets a collection of span elements I''m > interested in > X.each(function(item) { > // Event.observe(item, "click", > this.deleteitem.bindAsEventListener(item, item.id));}.bind(this));\ > > </code> > > so "item" is not the same sort of thing as "xspanid" above. Thus, I > tried it like this as well: > > <code> > Event.observe($(xspanid), "click", > this.deleteitem.bindAsEventListener(this, xspanid)); > </code> > > with exactly the same results. Only that last span that gets passed > through here gets an observer attached to it. > > I really don''t understand why it works just as well, to the extent > that it does, with either an element id or the whole element as the > first argument. But that''s another question. > > Thanks in advance for any help. > > Best > > ecb--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
ok. thanks. On Jul 22, 9:17 pm, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote:> Hi, > > This group is essentially closed to new posts. Use the new, better- > named, hopefully-spam-free group for Prototype and script.aculo.us: > > http://groups.google.com/group/prototype-scriptaculous/ > > prototype-scriptaculous-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > Hope this helps. > -- > T.J. Crowder > tj / crowder software / com > > On Jul 23, 3:00 am, ecb <s...-fLhsMdZZi9zzJm9tdWFm49BPR1lH4CV8@public.gmane.org> wrote: > > > Hi, > > > I need help with the following problem. > > > <code> > > var xspanid = .. whatever ... > > Event.observe(xspanid, "click", > > this.deleteitem.bindAsEventListener(this, xspanid)); > > </code> > > > the code above works (I''ve included two lines that I think are > > equivalent and both work the same, just . The problem I''m having is > > that deleteitem is only bound to the most recent span to which I > > attach this event, instead of to all of them. > > > on the other hand, if I run a loop on all the spans together and > > attach the events within that loop, then they all work. But only want > > to attach an observer once, at the moment the span is created. > > > The difference in the loop is that one is cycling through dom element, > > such as : > > <code> > > X = $$(''span.xspan''); // gets a collection of span elements I''m > > interested in > > X.each(function(item) { > > // Event.observe(item, "click", > > this.deleteitem.bindAsEventListener(item, item.id));}.bind(this));\ > > > </code> > > > so "item" is not the same sort of thing as "xspanid" above. Thus, I > > tried it like this as well: > > > <code> > > Event.observe($(xspanid), "click", > > this.deleteitem.bindAsEventListener(this, xspanid)); > > </code> > > > with exactly the same results. Only that last span that gets passed > > through here gets an observer attached to it. > > > I really don''t understand why it works just as well, to the extent > > that it does, with either an element id or the whole element as the > > first argument. But that''s another question. > > > Thanks in advance for any help. > > > Best > > > ecb--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---