Javascript Event System remove() Example

From KickApps Documentation

Jump to: navigation, search

For all of the examples on this page, we will assume that you already have created an event handler using the listen() method. This example event handler will be used for each of the following remove() examples.

function onPlayPageLoad() {
    // do something here! :)
}
var newEventId = Ka.events.listen('play-page-load', onPlayPageLoad);



Removing an event handler by ID

When you create a new event handler, the listen() method returns the new event handler's ID. To remove the event handler by ID, you would do the following:

Ka.events.remove(newEventId);

or

Ka.events.remove(5);
<pre>
<br /><br />
==Removing an event handler by callback==
Assuming you are not using anonymous callbacks, like the example code above, you may pass the name of your callback function as a parameter to remove().  Any event handlers that are using the specified callback will be removed.
<pre class="brush:js">
Ka.events.remove(onPlayPageLoad);



Removing an event handler by event name

If you would like to remove all event handlers for a specific event, you would do the following:

Ka.events.remove("play-page-load");