A Wired.com user account lets you create, edit and comment on Webmonkey articles. You will also be able to contribute to the Wired How-To Wiki and comment on news stories at Wired.com.
It's fast and free.
processing...Retrieve Sign In
Please enter your e-mail address or username below. Your username and password will be sent to the e-mail address you provided us.
processing...Welcome to Webmonkey
- edit articles
- add to the code library
- design and write a tutorial
- comment on any Webmonkey article
Sign In Information Sent
John Resigs addEvent Template
/skill level/
/viewed/
This template was written by John Resig. The original can be found at John Resig's addEvent function website.
Webmonkey is using it for its JavaScript Events reference page.
This code is in a wiki. If you have any advances to make to the original tutorial and code, please feel free to contribute.
What it Looks Like
It's a blank page, actually. This is meant to be a template for events you add in the HTML and JavaScript portions of the page.
The Code
<html>
<head>
<script>
// addEvent function by John Resig:
// http://ejohn.org/projects/flexible-javascript-events/
function addEvent( obj, type, fn ) {
if ( obj.attachEvent ) {
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
obj.attachEvent( 'on'+type, obj[type+fn] );
} else
obj.addEventListener( type, fn, false );
}
</script>
</head>
<body>
<!-- HTML for example event goes here -->
<script>
// Script for example event goes here
</script>
</body>
</html>
- This page was last modified 20:07, 22 September 2008.
/related_articles/
Special Offer For Webmonkey Users
WIRED magazine:
The first word on how technology is changing our world.
