DOMAssistant.Events Module

The DOMAssistantEvents module offers various methods for adding and removing handlers for one or several events on an element. It also contains functionality for stopping default actions and bubbling of events.

addEvent(evt, func)

Adds an event handler to the current element. Multiple event handlers are supported, and the receiving funtion will have an event object reference and a this reference to the element it occurred on, no matter what web browser. For accessibility reasons, please make sure to only apply click events to elements that can handle them without JavaScript enabled.

Parameters
evt
Event to apply, specified as a string, without the "on" prefix.
func
Function to handle the event, specified as a function reference (without parentheses) or an anonymous function.
Return value

Element which called the method.

Example calls

$("container").addEvent("click", getListing);

$("container").addEvent("click", function (){
alert("Hello darling!");
});

removeEvent(evt, func)

Removes an event handler from the current element. Works only for function references, and not anonymous functions.

Parameters
evt
Event to remove, specified as a string, without the "on" prefix.
func
Function to stop from handling the event, specified as a function reference (without parentheses).
Return value

Element which called the method.

Example calls

$("container").removeEvent("click", getListing);

preventDefault(evt)

Prevents the default action of an event. Can be called from any function, and is not a method of any element.

Parameters
evt
Event to prevent the default action of.
Return value

None.

Example calls

DOMAssistant.preventDefault(eventReference);

cancelBubble(evt)

Cancels the bubbling of an event. Can be called from any function, and is not a method of any element.

Parameters
evt
Event to cancel the bubbling of.
Return value

None.

Example calls

DOMAssistant.cancelBubble(eventReference);

Download DOMAssistant

All modules in one file

DOMAssistant 2.5.7, compressed
(22kb, 7kb Gzipped)
Intended for production usage.
DOMAssistant 2.5.7, complete
(43kb)
Intended for learning and development usage.

Individual modules

Get your copy