Sys.UI.DomEvent addHandlers Method

Adds a list of DOM event handlers to the DOM element that exposes the events. This member is static and can be invoked without creating an instance of the class.

Sys.UI.DomEvent.addHandlers(element, events, handlerOwner, autoRemove);

Term

Definition

element

The DOM element that exposes the events.

events

A dictionary of event handlers.

handlerOwner

(Optional) The object instance that is the context for the delegates that should be created from the handlers.

autoRemove

(Optional) A boolean value that determines whether the handler should be removed automatically when the element is disposed.

Exception type

Condition

Error.invalidOperation

(Debug) One of the handlers specified in events is not a function.

Use the addHandlers method to add a list of DOM event handlers to the element that exposes the event.

The events parameter takes a comma-separated list of name/value pairs in the format name:value, where name is the name of the DOM event and value is the name of the handler function. If there is more than one name/value pair, the list must be enclosed in braces ({}) to identify it as a single parameter. Multiple name/value pairs are separated with commas. Event names should not include the "on" prefix. For example, specify "click" instead of "onclick".

If handlerOwner is specified, delegates are created for each handler. These delegates are attached to the specified object instance, and the this pointer from the delegate handler will refer to the handlerOwner object.

This method can be accessed through the $addHandlers shortcut method.

The following example shows how to associate event handlers with an element by using the addHandlers method.


<script type="text/javascript">
    Sys.UI.DomEvent.addHandlers($get("Button1"), {click:processEventInfo,mouseover:processEventInfo,mouseout:processEventInfo});

    function processEventInfo(eventElement) {
        var result = '';
        result += eventElement.type;
        $get('Label2').innerHTML = result;
    }
 </script>


Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft