-1

Is it possible to Add Id to Toastr Notification? I need to identify one of several notifications when i close it. I use this plugin. https://github.com/CodeSeven/toastr

marmite
  • 113
  • 8

2 Answers2

0

That's an interesting question. It doesn't look like you can set an ID on the toastr itself. However, you can modify the button used to close the toastr:

toastr.options.closeHtml = '<button id="toastr1closebtn"><i class="icon-off"></i></button>';

That might be just as good for what you're trying to do.

I found the option to adjust the close button here.

L Becker
  • 685
  • 8
  • 28
-1

If you use toastr.options.closeButton = true; you can specify a function that should run when you close. That function will be passed the click event. The event can (hopefully) be used to figure out which notification was closed.

toastr.options.onCloseClick = function(event) {
  const closedElement = event.target.parentElement;
  // figure out which notfication was closed based on class, or text, or...
}

Perhaps there is a better way, but this is what I found based on the pretty sparse documentation and some tinkering with the plunker example they had.

jonahe
  • 4,820
  • 1
  • 15
  • 19