views:

133

answers:

1

Hi, have tried to use this my own function on FBJS:

function addEvent(event,fun,pars){
pars.event=event;
pars.listen=function(){ fun(this, pars);return false; };
this.addEventListener(event,pars.listen,false);
}

but dont work...if call:

obj=document.getElementById("id_element");
obj.addEvent(....);

Firebug return this error:am123456789_obj.addEvent is not a function

Any idea to resolve?

+1  A: 

You didn't create the addEvent function as a property of the object, so you can't call obj.addEvent(). The object simply doesn't know about that function.

With FBJS, your best bet is to simply pass the object in as a parameter.

function addEvent(obj,event,fun,pars){
pars.event=event;
pars.listen=function(){ fun(obj, pars);return false; };
obj.addEventListener(event,pars.listen,false);
}

obj=document.getElementById("id_element");
addEvent(obj,...);
zombat
Yes, already used this method, I thought of changing it to get more elegant code...but if is not possible click undo on Netbeans :) Much Thanks Zombat
Angelbit

related questions