Dismiss All Toasts
Sometimes you need to hide all visible toasts — for example, when navigating away from a page or when the user clicks "clear all".
Sometimes you need to hide all visible toasts — for example, when navigating away from a page or when the user clicks "clear all".
<button class="btn btn-secondary" onclick="dismissAll()">Clear All</button>
<script>
function dismissAll() {
document.querySelectorAll(".toast.show").forEach(el => {
bootstrap.Toast.getInstance(el)?.hide();
});
}
</script>
Use bootstrap.Toast.getInstance() to get an existing instance without creating a new one.