JavaScript

$e.removeGroup Function

Syntax

$e.removeGroup(groupName as string)

Arguments

groupNamestring

The name of the group of events to remove.

Description

Remove all events with the same group name.

Discussion

When you use the $e.add() command to add events, you can specify an optional 'group' name. This group name is used in the $e.removeGroup() function.

The $e.removeGroup() function allows you to remove events from elements that were initially set up with a 'group' name. This command is useful if you want to remove a large number of events from elements using a single function call.

Example

//Add some validation events to several form controls and assign an arbitrary group name of 'myForm'.
$e.add(['firstname','lastname','address','city','state','zip'],'blur',validateInput,null,false,'myForm');

$e.add('zip','blur',validateZip,null,false,'myForm');
//Now, 'zip' has two event handlers for its 'onblur' event.

$e.add('zip','blur',lookupCity);
//Now, 'zip' has three event handlers for its 'onblur' event. However, this last event 
// handler is not part of the 'myForm' group.
$e.removeGroup('myForm');
//Now all control have no event handlers attached to the 'onblur' event, except 'zip' 
//which still has 'lookupCity()' as the event handler for the 'onblur' event.
It is important to remove any events that were added to elements before destroying the HTML elements (either through direct DOM manipulation, or by setting the innerHTML of some containing element). For example, assume that your page has a large number of input controls. You use the $e.add() function to bind a validation event handler to the 'onblur' event on all of these controls and you assign a group name.

See Also