Skip to content

Need help with Bootstrap Toast message #5310

Closed Answered by glewe
glewe asked this question in Q&A
Discussion options

You must be logged in to vote

I figured it out.

The Javascript code needs to go into _scripts.astro. In this example I am using buttons to show the toast message. There might be other triggers in other use cases.
Here, the button tag has two attributes, data-bs-toggle="toast" and data-bs-target="<toast ID>":

...
<!--begin::Bootstrap Toasts-->
<script is:inline>
  const toastTriggerList = document.querySelectorAll('[data-bs-toggle="toast"]')
  toastTriggerList.forEach(btn => {
    btn.addEventListener('click', event => {
      event.preventDefault();
      const toastEle = document.getElementById(btn.getAttribute('data-bs-target'));
      const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastEle);
      toast…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by glewe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant