My favorites | Sign in
Project Home Downloads Wiki Issues Source
reglib's cross-browser event adder
Updated Feb 4, 2010 by

The Event Adder

Reglib has a cross-browser event adder that uses object detection to either call Element.addEventListener() or Element.attachEvent(). It keeps an internal cache of added events and removes them onunload in order to reduce the likelihood of memory leaks. Here are the event functions:


var mem = reg.addEvent(element, event, handler, capture);

element is the element node to add the event to.

event is a string representing the event, such as "click" or "focus".

handler is a function that accepts an event object as its only parameter. Within handler, this always refers to the element the event was added to, which may be the same or an ancestor of the element returned by reg.getTarget(event).

capture is an optional boolean which defaults to false. If true it causes the event to be handled in the capturing phase (on clients that support it).

mem is a signifier value that can be used later to remove this event.



mem is a signifier value that was returned from addEvent() which will remove that event.



Returns the target element of the event. Uses object detection to return the appropriate result since clients differ on how to get the target.



Cancels the default action, such as a link causing the page to be replaced by a new URL. Uses object detection to call the appropriate method since clients differ on how to do this.



Prevents the event object from further bubbling.

Sign in to add a comment
Powered by Google Project Hosting