Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap dismissible alert not working

I have been working out this bug for an hour now and can't seem to find any solution to it! I'm using bootstrap and i have a dismissible alert but when i click on the x to dismiss nothing happens.

Here's my div

<div class="alert alert-warning alert-dismissible" role="alert">
  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  <strong>Warning!</strong> Still on beta stage.
</div>

And here is my footer where i include the js files

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
like image 294
Dragotic Avatar asked Oct 24 '16 18:10

Dragotic


People also ask

Which bootstrap class can create dismissible alert?

alert-dismissible class to the alert container. Then add class="close" and data-dismiss="alert" to a link or a button element (when you click on this the alert box will disappear).

Which bootstrap 4 class is used to add links inside an alert message?

Use the . alert-link utility class to quickly provide matching colored links within any alert. This is a primary alert with an example link.


2 Answers

If you are using Bootstrap 5.0 it seems in the bootstrap.js code the data-dismiss selector has changed to data-bs-dismiss. So I just had to change data-dismiss="modal" to data-bs-dismiss="modal" and it worked.

like image 75
Hmerman6006 Avatar answered Oct 12 '22 20:10

Hmerman6006


I'm using Bootstrap v5.1 now and according to the doc the template is

<div class="alert alert-warning alert-dismissible fade show" role="alert">
  <strong>Holy guacamole!</strong> You should check in on some of those fields below.
  <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>

Reference: https://getbootstrap.com/docs/5.1/components/alerts/#dismissing

like image 25
Brody Chen Avatar answered Oct 12 '22 20:10

Brody Chen