Search results

Action Buttons

You can include action buttons to the toast control by adding the buttons property. The collection of Essential JS 2 button models can be bound to the model property inside the buttons property. You can also include the click event callback function for each button.

Source
Preview
index.js
index.html
ej.base.enableRipple(true);

//Initialize Toast component

    var toast = new ej.notifications.Toast({
    title: 'Anjolie Stokes',
    content: '<p><img src="./laura.png"></p>',
    position: { X: "Right", Y: "Bottom" },
    width: 230,
    height: 250,
        buttons : [{
        model: { content: "Ignore"  }, click: btnClick
    }, {
      model: { content: "reply" }
    }]
    });

//Render initialized Toast component
    toast.appendTo('#elementToastTime');

ele = document.createElement("button");
ele.textContent = "Show Toast"
ele.classList.add('e-btn');
ele.id = "show_toast";
document.body.appendChild(ele);

ele.onclick = function () {
  toast.show();
};

function btnClick(e) {
 let toastEle = ej.base.closest(e.target, '.e-toast');
 toast.hide(toastEle);
}
<!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="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet">
    
    
<script src="//cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element"></div>
        <div id="elementToastTime"></div>
        <br><br>
        <div id="result"></div>
    </div>


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

See Also