Elementals.js

Latest Version: 2.0 RC 3 14 March 2017

Method _.eventAdd

Summary:

Attaches an event to an Element in a cross-browser compatible manner. The resulting event will pass the Event object to the callback even in older versions of Internet Explorer, and that Event will have correct Event.target and Event.currentTarget values.

Calling Convention:
_.eventAdd(Element, event, callback)
Parameters:
Element
The Element you want the event attached to
event
The name of the JavaScript event you want to hook, such as "change", "submit', or "over".
callback
The function to be called when the event occurs.
Returns:
Nothing

Example

JavaScript

_.eventAdd(
	document.getElementById('testForm'),
	'submit',
	function(e) {
		console.log('attempted to send ', e.target);
	}
);

Note:

For the most part, you can treat this as you would Element.addEventListener where "useCapture" is always true. See MDN's Element.addEventListener reference page for more information. It simply wraps Element.attachEvent for legacy IE compatibility.