https://getbootstrap.com/docs/4.0/components/alerts/
Exploring the world of Bootstrap 4.0, I came across an interesting method in the documentation:
$('.alert').alert()
This method allows an alert to listen for click events on its descendant elements that have the data-dismiss="alert" attribute. (This is not required when using the data-api’s auto-initialization.)
In order to test this method, I decided to try some code snippets:
$(document).off('.alert.data-api'); // executed successfully
$('.alert').alert(); // seemingly does nothing
<div id='mydiv' class="alert alert-warning alert-dismissible fade show" role="alert">
text
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
Surprisingly, the alert() method appears to be ineffective in making the button work as expected. This raises the question: why is it not functioning correctly?