Add dynamic template in EJ2 JavaScript Toast control

10 May 20233 minutes to read

Toast supports to change templates dynamically with displaying in multiple toasts. You can change the toast properties while calling in the show method.


//Initialize Toast component
var toast = new ej.notifications.Toast({
    timeOut: 0,
    target: document.body,
    position: { X: 'Right', Y: 'Bottom' },
    click: onClick

var toastFlag = 0;
var toasts = [ { template: '2 Mail has received'},{ template: 'User Guest Logged in'},{ template: 'Logging in as Guest'},{ template: 'Ticket has reserved '},{ template: '#templateToast' }];

//Render initialized Toast component

document.getElementById('show_toast').onclick = function () {[toastFlag]);
  if (toastFlag === (toasts.length)) {
      toastFlag = 0;

function onClick(e ) {
 e.clickToClose = true;
<!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="index.css" rel="stylesheet">
    <link href="" 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>
        <div id="templateToast" style="display: none;color:red"> System affected by virus !!! </div>

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