If I have 5 links with onClick event listeners, setup like so: ... moveLinks[i].observe(''click'',this.moveObject.bind(this)); How do I know which link was clicked on? I need the ID. Thanks! Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 6/15/07, Daniel Eben Elmore <danielelmore-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > If I have 5 links with onClick event listeners, setup like so: > > ... > moveLinks[i].observe(''click'',this.moveObject.bind(this)); > > > How do I know which link was clicked on? I need the ID. > > > Thanks! > DanielI''m pretty new to prototype but in the moveObject function wouldn''t this.id do the job? Cheers Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 6/15/07, Daniel N <has.sox-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 6/15/07, Daniel Eben Elmore <danielelmore-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > If I have 5 links with onClick event listeners, setup like so: > > > > ... > > moveLinks[i].observe(''click'',this.moveObject.bind(this)); > > > > > > How do I know which link was clicked on? I need the ID. > > > > > > Thanks! > > Daniel > > > > I''m pretty new to prototype but in the moveObject function wouldn''t > > this.id do the job? > > Cheers > Daniel >Just did a quick visit to the docs It seems that this.readAttribute( ''id'' ) would probably be a better bet. Cheers Daniel --~--~---------~--~----~------------~-------~--~----~ 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, yes that will work _if_ I remove the bind(this) method, but I need to access the scope of the original object that setup the observer, so I need that there. And that is where I''m lost. :) Daniel -----Original Message----- From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Daniel N Sent: Thursday, June 14, 2007 10:51 PM To: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails-spinoffs] Re: Event Listener, getting the element observed On 6/15/07, Daniel N <has.sox-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: On 6/15/07, Daniel Eben Elmore < danielelmore-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: If I have 5 links with onClick event listeners, setup like so: ... moveLinks[i].observe(''click'',this.moveObject.bind(this)); How do I know which link was clicked on? I need the ID. Thanks! Daniel I''m pretty new to prototype but in the moveObject function wouldn''t this.id do the job? Cheers Daniel Just did a quick visit to the docs It seems that this.readAttribute( ''id'' ) would probably be a better bet. Cheers Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 6/15/07, Daniel Eben Elmore <danielelmore-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hi, yes that will work _if_ I remove the bind(this) method, but I need to > access the scope of the original object that setup the observer, so I need > that there. And that is where I''m lost. :) > > > > Daniel > > > > -----Original Message----- > From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Daniel N > Sent: Thursday, June 14, 2007 10:51 PM > To: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails-spinoffs] Re: Event Listener, getting the element observed > > > On 6/15/07, Daniel N <has.sox-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On 6/15/07, Daniel Eben Elmore < danielelmore-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > If I have 5 links with onClick event listeners, setup like so: > > ... > moveLinks[i].observe(''click'',this.moveObject.bind(this)); > > > How do I know which link was clicked on? I need the ID. > > > Thanks! > Daniel > > > I''m pretty new to prototype but in the moveObject function wouldn''t > > this.id do the job? > > Cheers > Daniel > > Just did a quick visit to the docs > > It seems that > > this.readAttribute( ''id'' ) would probably be a better bet. > > Cheers > DanielCould you add a reference to the object in the bind call as the first argument for moveObject moveLinks[i].observe(''click'',this.moveObject.bind( this, moveLinks[i] )); What is "this" in this situation? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 6/15/07, Daniel N <has.sox-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 6/15/07, Daniel Eben Elmore <danielelmore-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi, yes that will work _if_ I remove the bind(this) method, but I need > > to > > access the scope of the original object that setup the observer, so I > > need > > that there. And that is where I''m lost. :) > > > > > > > > Daniel > > > > > > > > -----Original Message----- > > From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [mailto: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Daniel N > > Sent: Thursday, June 14, 2007 10:51 PM > > To: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > Subject: [Rails-spinoffs] Re: Event Listener, getting the element > > observed > > > > > > On 6/15/07, Daniel N <has.sox-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On 6/15/07, Daniel Eben Elmore < danielelmore-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > If I have 5 links with onClick event listeners, setup like so: > > > > ... > > moveLinks[i].observe(''click'',this.moveObject.bind(this)); > > > > > > How do I know which link was clicked on? I need the ID. > > > > > > Thanks! > > Daniel > > > > > > I''m pretty new to prototype but in the moveObject function wouldn''t > > > > this.id do the job? > > > > Cheers > > Daniel > > > > Just did a quick visit to the docs > > > > It seems that > > > > this.readAttribute( ''id'' ) would probably be a better bet. > > > > Cheers > > Daniel > > > Could you add a reference to the object in the bind call as the first > argument for moveObject > > moveLinks[i].observe(''click'',this.moveObject.bind( this, moveLinks[i] )); > > What is "this" in this situation? > > >I''ve found an article that goes into events in a fair bit of depth. http://encytemedia.com/blog/articles/2006/02/08/working-with-events-in-prototype --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
This should do it: moveLinks.each(function(el){ el.observe(''click'', function(e){ alert(Event.element(e).getAttribute(''id'')); Event.stop(e); }) }) -- View this message in context: http://www.nabble.com/Event-Listener%2C-getting-the-element-observed-tf3925459.html#a11138682 Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greetings, You could also use the "bindAsEventListener" property of the function to return a function closure that will guarantee that an event object is sent as the first parameter in the call back. Once in the call back you can retrieve your event''s target object via the Event.element function. You can leverage bind and bindAsEventListener in many ways to attach parameters to the call back such that when it is executed you have the parameters that were attached upon its "binding" in the argument scope. Here is an article more about that idea http://positionabsolute.net/blog/2007/04/function-bind.php On Jun 15, 8:40 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This should do it: > > moveLinks.each(function(el){ > el.observe(''click'', function(e){ > alert(Event.element(e).getAttribute(''id'')); > Event.stop(e); > })}) > > -- > View this message in context:http://www.nabble.com/Event-Listener%2C-getting-the-element-observed-... > Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---