Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
Bootstrap 5 second toast not showing up

Hello guys i have problem with second toast which is not displaying.

HTML:

<div class="toast-container position-fixed bottom-0 end-0 p-3">
<!-- FIRST -->
  <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
    <div class="toast-header">
    <i class="fas fa-duck"></i>
      <strong class="me-auto">Bootstrap</strong>
      <small class="text-muted">just now</small>
      <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
    </div>
    <div class="toast-body">
      See? Just like this.
    </div>
  </div>

<!-- SECOND -->
  <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
    <div class="toast-header">
    <i class="fas fa-duck"></i>
      <strong class="me-auto">Bootstrap</strong>
      <small class="text-muted">just now</small>
      <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
    </div>
    <div class="toast-body">
      See? Just like this.
    </div>
  </div>

</div>

Script looks like

        <script>
window.onload = (event)=> {
 let myAlert = document.querySelector('.toast');
 let bsAlert = new  bootstrap.Toast(myAlert);
 bsAlert.show();
}
                </script>

My question is how can i fix it to display second toast on my site

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

show() only works for one element , you have to make a loop for all your toasts if you want to show them in one event:

$.each($('.toast'),function(i,item){ new bootstrap.Toast(item).show();});
about 4 years ago · Juan Pablo Isaza Relatório

0

I just created a class named start-toast for all of the messages that will be displayed when the page is ready, and then applied the toast() method with the parameter 'show', to all of the messages with that custom class . According to the documentation, you should be able to also stack them up with the toast-container class.

  $(document).ready(function(){
            $(".start-toast").toast('show');
            });
       
        <!-- JQuery - to handle with with the DOM easier !-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <!-- Bootstrap -->
    <link crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
          integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" rel="stylesheet">
    <link href='https://unpkg.com/boxicons@2.1.1/css/boxicons.min.css' rel='stylesheet'>
    <script crossorigin="anonymous"
            integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
            src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
      <div class="position-fixed bottom-0 end-0 " style="z-index: 11">
            <div aria-atomic="true" aria-live="assertive" class="toast hide start-toast" id="welcomeToast" role="alert">
                <div class="toast-header">
                    <strong>🙂</strong>
                    <strong class="me-auto">Welcome!!</strong>
                    <small>0 min ago</small>
                    <button aria-label="Close" class="btn-close" data-bs-dismiss="toast" type="button"></button>
                </div>
                <div class="toast-body">
                    How are you doing ?
                </div>
            </div>
        </div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda