Close the toast with click/tap

17 Feb 20221 minute to read

By default, the toasts are expired based on the TimeOut value. You can customize the toast hiding process with click/tap action by setting the event args in the clicked callback function with static Toast.

<div class="control-section" style="width:400px;margin:0 auto;">
    @Html.EJS().Toast("element").Title("Matt sent you a friend request").Position(p => p.X("Right").Y("Bottom")).Content("You have a new friend request yet to accept").TimeOut(0).Click("onClick").Render()
    <div class="row">
        @Html.EJS().Button("show_toast").Content("Show Toast").CssClass("e-btn").Render()
<script type="text/javascript">
        () => {
            var toastObj = document.getElementById('element').ej2_instances[0];
   = document.body;
        }, 200);
    document.getElementById("show_toast").addEventListener('click', function () {
        var toastObj = document.getElementById('element').ej2_instances[0];;
    function onClick(e) {
        e.clickToClose = true;
public class HomeController : Controller

    public ActionResult Index()
        return View();