File Under: JavaScript

John Resigs addEvent Template

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.

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>