This is a test site. Any changes will be lost!

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:

  1. 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.
  2. Event: A string indicating the event ('click', 'keypress', etc.).
  3. Callback: The function to be called when the event fires.
  4. Associated object: Object to which your callback will have access; often the callback's parent object.
  5. Scope: Boolean — if true, the callback runs in the scope of the associated object.

Examples:

  1. YAHOO.util.Event.addListener(window, 'load', fnDoSomething); listens for the window contents to finish loading and then calls the function fnDoSomething
  2. 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);