Show different types of toast in EJ2 JavaScript Toast control

10 May 20234 minutes to read

The Essential JS 2 toast has the following predefined styles that can be defined using the cssClass property for achieving different types of toast:

Class Description
e-toast-success Represents a positive toast
e-toast-info Represents an informative toast
e-toast-warning Represents a toast with caution
e-toast-danger Represents a negative toast

//Initialize Toast component
var toasts = [
  { title: 'Warning !', content: 'There was a problem with your network connection.', cssClass: 'e-toast-warning' },
  { title: 'Success !', content: 'Your message has been sent successfully.', cssClass: 'e-toast-success'},
  { title: 'Error !', content: 'A problem has been occurred while submitting your data.', cssClass: 'e-toast-danger' },
  { title: 'Information !', content: 'Please read the comments carefully.', cssClass: 'e-toast-info' } 

var toastFlag = 0;
var toast = new ej.notifications.Toast({
    title: 'Matt sent you a friend request',
    content: 'You have a new friend request yet to accept',
    target: document.body,
    position: { X: 'Right', Y: 'Bottom' }


document.getElementById('show_toast').onclick = function () {[toastFlag]);
  if (toastFlag === (toasts.length)) {
      toastFlag = 0;
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Toast</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Toolbar Controls">
    <meta name="author" content="Syncfusion">
    <link href="" rel="stylesheet">
    <link href="index.css" rel="stylesheet">
<script src="" type="text/javascript"></script>
<script src="" type ="text/javascript"></script>

    <div id="container">
        <div class="row"> <button class="e-btn" id="show_toast"> Show Toast</button> </div>
        <div id="element"></div>
        <div id="result"></div>

var ele = document.getElementById('container');
if(ele) { = "visible";
<script src="index.js" type="text/javascript"></script>