Sticky toastr onclick event of close button

Cragly picture Cragly · Dec 13, 2013 · Viewed 16.6k times · Source

Is there a way I can perform an action after a user either clicks on the notification or clicks on the close button? At the moment I can do the first option using the options.onclick event. However I can not see how I can do this on the close button. Alternatively is there a way it could perform my action on the notification fading out?

toastr.options = {
    "closeButton": true,
    "timeOut": "0",
    "extendedTimeOut": "0"
};
toastr.options.onclick = function () {
    console.log("Notification clicked");
};
toastr.success("Success, Whooo!!");

Answer

Dave picture Dave · Dec 13, 2013

You can't do it nicely on click, because there is no callback. You could use a jquery live handler on the button.

About the notification after fading out, use this;

 toastr.options.onHidden = function() { console.log("onHide"); };