...

View Full Version : How can I make addEventListener, and attachEvent helper function?



alcatraz678
09-14-2008, 02:20 PM
Hi guys, I'm learning how to make a helper function for the attachEvent and addEventListener methods which will take 3 or 2 arguments. I'm a newbie, so im trying to practice this kind of programming to advance my learning...


$e('click', fnction, false);

Is this possible? I want to make my own function which will take 2 or 3 arguments, and test whether addEventListener or the attachEvent is available in the browser.



var $e = function(evnt, fnc, prpgtion) { //i want prpgtion to become optional.


Then I also want to test whether the method is available in the browser, then it will decide which will be used: the addEventListener or attachEvent

I dont know how to make one, please teach me and explain to me how to code this kind of helper function...



var $e = function(evnt, fnction, prpgt) {
var use;
if (typeof this.addEventListener != 'undefined')
{
use = this.addEventListener(evnt, fnction, prpgt);
} else if(typeof this.attachEvent != 'undefined')
{
evnt += "on";
use = this.attachEvent(evnt, fnction);
}
return use;
}


This is the one that will check the browser, I dont even know if it is correct

Thanks

shyam
09-14-2008, 06:25 PM
http://www.quirksmode.org/blog/archives/2005/09/addevent_recodi.html

alcatraz678
09-15-2008, 04:33 AM
thanks shyam, the link was very helpful



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum