Development:YUI event utility
From MoodleDocs
Yahoo Event Utility Methods
addListener(...)
Used to add event listeners to an element or elements within a page
YAHOO.util.Event.addListener(str | el ref | arr target[s], str event, fn callback[, obj associated object, b scope);
Arguments:
- Element or elements: You may pass a single element or group of elements in an array; references may be id strings or direct element references.
- Event: A string indicating the event ('click', 'keypress', etc.).
- Callback: The function to be called when the event fires.
- Associated object: Object to which your callback will have access; often the callback's parent object.
- Scope: Boolean — if true, the callback runs in the scope of the associated object.
Examples:
- YAHOO.util.Event.addListener(window, 'load', fnDoSomething); listens for the window contents to finish loading and then calls the function fnDoSomething
- YAHOO.util.Event.addListener("myDiv", 'click', fnDoAnotherThing); listens for when the element with the ID myDiv is clicked upon and then calls the function fnDoAnotherThing
preventDefault(e)
Used to prevent an elements default behaviour
YAHOO.util.Event.preventDefault(e);