Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 

Top 10 Custom JavaScript Functions Of All Time

By Dustin Diaz
2006-08-22


10) addEvent()

Surely a staple to event attachment! Regardless to what version you use written by whatever developer, it does what it says it does. And of course as you might of known, I’ve put together quite a handy version myself recently of addEvent() with some help from the contest winner and Mark Wubben along with a few minor syntax adjustments. But just to be fair to Scott Andrew, here is the original that started it all.

Scott Andrew’s original addEvent() function

function addEvent(elm, evType, fn, useCapture) {

if (elm.addEventListener) {
elm.addEventListener(evType, fn, useCapture);
return true;
}
else if (elm.attachEvent) {
var r = elm.attachEvent('on' + evType, fn);
return r;
}
else {
elm['on' + evType] = fn;
}
}


Tutorial Pages:
» Top 10 custom JavaScript functions of all time
» 10) addEvent()
» 9) addLoadEvent()
» 8) getElementsByClass()
» 7) cssQuery()
» 6) toggle()
» 5) insertAfter()
» 4) inArray()
» 3, 2, & 1) getCookie(), setCookie(), deleteCookie()
» Last but not least, a bonus function: The Prototype Dollar Function
» And so will they all…


 | Bookmark
Related Tutorials:
» JavaScript Debugging Techniques with Firebug
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Essential Javascript -- A Javascript Tutorial
» Submit Forms Conditionally using JavaScript
» How to Setup a Randomising Function

Advertise with Us!


Tutorials Scripts Web Hosting Developer Manuals
Resources