jQuery custom events

Trigger custom jQuery event:

$(document).trigger('user.add'); // trigger custom event

$(document).on('user.add', function () {
    // run code when custom event was triggered
});


Trigger custom jQuery event with passing custom parameter:

$(document).trigger('user.remove', [userId]); // trigger custom event

$(document).on('user.remove', function (event, userId) {
    console.log(userId);
});

Leave a Reply

Your email address will not be published. Required fields are marked *