obj = {
click : function (msg ){
alert(msg);
}
}
var link = document.getElementById('link');
link.addEventListener('click',obj.click,false);
The above code is working, but i need to pass the ‘msg’ in parameters how can i do? in case if i pass the parameter like this :
link.addEventListener('click',obj.click('message'),false);
then, it is calling the function, event without clicking on the link. for this how can i my object to only get call on the click as well with parameter in the function?
Any one help me?
thanks
You need to use an anonymous function as a callback:
The example above was taken from the Mozilla developer documentation.