1<!-- Bootstrap 5 Toasts -->
2<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
3 <div class="toast-header">
4 <img src="..." class="rounded me-2" alt="..." />
5 <strong class="me-auto">Bootstrap</strong>
6 <small>11 mins ago</small>
7 <button
8 type="button"
9 class="btn-close"
10 data-bs-dismiss="toast"
11 aria-label="Close"
12 ></button>
13 </div>
14 <div class="toast-body">Hello, world! This is a toast message.</div>
15</div>
1<!doctype html>
2<html lang="en">
3
4 <head>
5 <meta charset="utf-8">
6 <meta name="viewport" content="width=device-width, initial-scale=1">
7 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css">
8 </head>
9
10 <body>
11
12 <div class="container mt-5">
13
14 <!-- button to initialize toast -->
15 <button type="button" class="btn btn-primary" id="toastbtn">Initialize toast</button>
16
17 <!-- Toast -->
18 <div class="toast">
19 <div class="toast-header">
20 <strong class="mr-auto">Bootstrap</strong>
21 <small>11 mins ago</small>
22 <button type="button" class="ml-2 mb-1 close" data-dismiss="toast">
23 <span>×</span>
24 </button>
25 </div>
26 <div class="toast-body">
27 Hello, world! This is a toast message.
28 </div>
29 </div>
30
31 </div>
32
33
34 <!-- Popper.js first, then Bootstrap JS -->
35 <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
36 <script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js"></script>
37 <script>
38 document.getElementById("toastbtn").onclick = function() {
39 var toastElList = [].slice.call(document.querySelectorAll('.toast'))
40 var toastList = toastElList.map(function(toastEl) {
41 // Creates an array of toasts (it only initializes them)
42 return new bootstrap.Toast(toastEl) // No need for options; use the default options
43 });
44 toastList.forEach(toast => toast.show()); // This show them
45
46 console.log(toastList); // Testing to see if it works
47 };
48
49 </script>
50 </body>
51
52</html>
1<!-- Flexbox container for aligning the toasts -->
2<div aria-live="polite" aria-atomic="true" class="d-flex justify-content-center align-items-center" style="min-height: 200px;">
3
4 <!-- Then put toasts within -->
5 <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
6 <div class="toast-header">
7 <img src="..." class="rounded mr-2" alt="...">
8 <strong class="mr-auto">Bootstrap</strong>
9 <small>11 mins ago</small>
10 <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
11 <span aria-hidden="true">×</span>
12 </button>
13 </div>
14 <div class="toast-body">
15 Hello, world! This is a toast messag e.
16 </div>
17 </div>
18</div>
1<!-- Flexbox container for aligning the toasts -->
2<div aria-live="polite" aria-atomic="true" class="d-flex justify-content-center align-items-center" style="min-height: 200px;">
3
4 <!-- Then put toasts within -->
5 <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
6 <div class="toast-header">
7 <img src="..." class="rounded mr-2" alt="...">
8 <strong class="mr-auto">Bootstrap</strong>
9 <small>11 mins ago</small>
10 <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
11 <span aria-hidden="true">×</span>
12 </button>
13 </div>
14 <div class="toast-body">
15 Hello, world! This is a toast message.
16 </div>
17 </div>
18</div>
1<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
2 <div class="toast-header">
3 <img src="..." class="rounded mr-2" alt="...">
4 <strong class="mr-auto">Bootstrap</strong>
5 <small>11 mins ago</small>
6 <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
7 <span aria-hidden="true">×</span>
8 </button>
9 </div>
10 <div class="toast-body">
11 Hello, world! This is a toast message.
12 </div>
13</div>