6

I want to use toastr to notify the user. I have followed this guide to set it up. But I get the error message: Uncaught TypeError: toastr is not a function. I have looked at the network tab and the files are loading properly. Tried with a cdn to be sure. But no luck. This is how I tried to use it:

    toastr('Are you the 6 fingered man?');

As in the demo. Any suggestions about what I am doing wrong?

klugjo
  • 19,422
  • 8
  • 57
  • 75
AllramEst
  • 1,319
  • 4
  • 23
  • 47
  • Are you including toastr script **before** this line? – sabithpocker Dec 19 '17 at 09:49
  • yes. and solved it. Had to declare`toastr` like this `Command: toastr["success"]("test message", "test")`. – AllramEst Dec 19 '17 at 09:50
  • So you might want to either post an answer to your own question, describing in detail what the problem was and what needed to be done to solve it, or delete your own post. – connexo Dec 19 '17 at 09:52

3 Answers3

8

According to the documentation you linked, it should be used like this:

toastr.info('Are you the 6 fingered man?')

You forgot to call the function info().

tobiso
  • 521
  • 3
  • 11
6

You need to use toastr functions as per below.

See documentation

// Display a warning toast, with no title
toastr.warning('My name is Inigo Montoya. You killed my father, prepare to die!')

// Display a success toast, with a title
toastr.success('Have fun storming the castle!', 'Miracle Max Says')

// Display an error toast, with a title
toastr.error('I do not think that word means what you think it means.', 'Inconceivable!')

// Immediately remove current toasts without using animation
toastr.remove()

// Remove current toasts using animation
toastr.clear()

// Override global options
toastr.success('We do have the Kapua suite available.', 'Turtle Bay Resort', {timeOut: 5000})
Shalitha Suranga
  • 1,138
  • 8
  • 24
2

Please use toastr with info, warning,success,error or option.

toastr.info('Are you the 6 fingered man?');
Coding E
  • 21
  • 4