Rolf, check this fiddle: http://jsfiddle.net/4E4P4/

So you could do var myFn = function(event){ // etc

and then 

el.addEvent('type', myFn); // same for removeEvent

When you use the parenthesis inside the addEvent function parameters like 
`el.addEvent( 'blur', myFunction(event))` you are actually calling/running 
your function instead of just referring/pointing to it. So use just 
"myFunction".



On Thursday, 24 July 2014 13:54:58 UTC+2, Roo wrote:
>
> Hi all,
>
> Bit of a newbie question this.
>
> I usally add my events to elements like this using an anonymous function I 
> think its called.
>
> $$('.myClass').addEvent( 'blur', function(e){
> console.log(e.target.id); <--- I have the event available here
> }
>
> I now have a need to attach and detach an event dynamically so I want to 
> declare the function like so;
>
> var myFunction(event){
>
> }
>
> then attach like;
>
> $$('.myClass').addEvent( 'blur', myFunction(event))
>
> But I dont know how to ensure that the element and event get bound to the 
> function.
>
> Thanks
> Rolf
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"MooTools Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to