Search code examples
javascripttoastr

Toastr "options" don't work


I create notification message using Toastr. My notification message is shows, but I can't use any options, I put some options but they don't work.

$('#editButton').click(function() {
  toastr.success('System successfully saved');
  toastr.options.timeOut = 5000;
  toastr.options.positionClass = toast - top - center;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css" rel="stylesheet">

<button class="button" id="editButton" type="submit" aria-hidden="true">Edit</button>


Solution

  • The toast displays when you call success(). So you need to set your options before that.

    Also toast-top-center is not a javascript identifier, it needs to be in quotes.

    $('#editButton').click(function () {
        toastr.options.timeOut = 5000;
        toastr.options.positionClass = 'toast-top-center';
        toastr.success('System successfully saved');
    });