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
Asked
Active
Viewed 829 times
2 Answers
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
-
Thank you, it is really useful in my project. – marmite Aug 23 '17 at 06:41
-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