In my page, the response from server is displayed using this alert:
<div id="yes" class="alert alert-success" role="alert" style="display: none;">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<strong>Pronto!</strong> cadastro efetuado com sucesso!
</div>
Is there any way to when I click in the close button from the alert, it be hide instead removed from page? I try this (following instructions from here), without success:
$('#my-alert').on('close.bs.alert', function () {
$(this).hide();
})
UPDATE
I also try this:
$('button.close').on("click", function(){
$(this).parent().hide();
});
but still the same problem, when I click in the close button, the alert is removed.
Closing Alerts To close the alert message, add a .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).
We need to add the class and role fields as alert. Then the element will work as an Alert. Now, we will create a button to dismiss the alert. We can either create an alert inside the element using the data-dismiss field of the button as alert or outside the container a javascript function.
Bootstrap Alerts are used to provide an easy way to create predefined alert messages. Alert adds a style to your messages to make it more appealing to the users. There are four classes that are used within <div> element for alerts. .alert-success.
Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.
Use the bootstrap close.bs.alert event:
$('.alert').on('close.bs.alert', function (event) {
event.preventDefault();
$(this).addClass('hidden');
});
I have tried these solutions, but not working for me. You can do it with simply remove "data-dismiss" attribute from your markup and create new function :
$('.alert').on('click','.close',function(){
$(this).closest('.alert').slideUp();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With