If i can do it without it i would prefer not adding more weight to the code
but thanks for thnfo

-----Original Message-----
From: duclet [mailto:[email protected]] 
Sent: Tuesday, 10 May 2011 3:38 AM
To: MooTools Users
Subject: [Moo] Re: Common functions for events

Why not just use event delegation? Add it in from More and you have
it:

http://jsfiddle.net/LWUX3/2/


On May 9, 11:41 am, "Steve Onnis" <[email protected]> wrote:
> I did it like that cause i didn’t think the event argument would get
passed
> in. Now i know :) thanks
>
>
>
>
>
>
>
> -----Original Message-----
> From: Izzy [mailto:[email protected]]
> Sent: Tuesday, 10 May 2011 12:46 AM
> To: MooTools Users
> Subject: [Moo] Re: Common functions for events
>
> You're really basically there, except you're event handler is a bit
> redundant.
>
> function submitFunction(ev) {
>     ev.stop();
>     console.log(this)
> }
>
> $("f1").addEvent("submit", function(ev) {
>     submitFunction.attempt(ev, $("f1"))
> });
>
> Why are you wrapping the submitFunction inside an anonymous function?
>
> By definition, the "this" inside that function will the the element it
> fires on.
>
> Just do:
>
> $('f1').addEvent('submit', submitFunction);
>
> and call it a day ;)
>
> On May 9, 8:35 am, "Steve Onnis" <[email protected]> wrote:
> > I am wondering which is the best way to use a common function for
element
> > events.
>
> > For example, i have a form that loads on the page, then on that same
page
> i
> > have an ajax window that opens that has other forms and i want to assign
> the
> > same submit event function for both forms. Because i need to add the
> events
> > to the forms in the ajax window programmatically i want to create a
> generic
> > function which i can assign to multiple forms.
>
> > Is this the best way to do it?
>
> >http://jsfiddle.net/LWUX3/
>
> > Steve

Reply via email to