How to close the toast with click/tap in EJ2 JavaScript Toast
04 Sep 20263 minutes to read
By default, the toasts are expired based on the timeOut value. The Toast hiding process can be customized with click/tap action by setting the event args in the clicked callback function with static Toast.
ej.base.enableRipple(true);
//Initialize Toast component
var toast = new ej.notifications.Toast({
title: 'Matt sent you a friend request',
content: 'You have a new friend request yet to accept',
timeOut: 0,
target: document.body,
position: { X: 'Right', Y: 'Bottom' },
click: onClick
});
//Render initialized Toast component
toast.appendTo('#element');
toast.show();
document.getElementById('show_toast').onclick = function () {
toast.show();
}
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="https://cdn.syncfusion.com/ej2/35.1.37/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.1.37/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div class="row"> <button class="e-btn" id="show_toast"> Show Toast</button> </div>
<div id="element"></div>
<br><br>
<div id="result"></div>
<div id="templateToast" style="display: none;color:red"> System affected by virus !!! </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>