can.trigger

  • function
 

Trigger an event on an object.

can.trigger(target, eventName[, args])

Parameters

  1. target {Object}

    The object to trigger the event on.

  2. eventName {String}

    The event to trigger.

  3. args {Array<*>}Optional

    The event data.

can.trigger(target, eventName) triggers an artificial event on an object and fires all associated callback handlers that were bound to it. This is exceptionally handly for simulating events. Such as the following:

var button = document.createElement('button');

can.bind.call(button, 'click', function() {
    console.log('I have been clicked');
})

can.trigger(button, 'click');