admin管理员组文章数量:1430001
As the title states, I'd like to know the best way to hide an alert so that we can have another alert without reloading the page. There are several answers on here for BS3, but I'm hoping there's a better solution for BS4.
Here's my HTML:
<div style="display: none;" class="alert alert-danger alert-with-icon" data-notify="container">
<div class="container">
<div class="alert-wrapper">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<i class="nc-icon nc-simple-remove"></i>
</button>
<div class="message"><i class="nc-icon nc-bell-55"></i>
My alert message.
</div>
</div>
</div>
</div>
And I'm using this to trigger the alert to being opened:
$('.alert').show();
As the title states, I'd like to know the best way to hide an alert so that we can have another alert without reloading the page. There are several answers on here for BS3, but I'm hoping there's a better solution for BS4.
Here's my HTML:
<div style="display: none;" class="alert alert-danger alert-with-icon" data-notify="container">
<div class="container">
<div class="alert-wrapper">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<i class="nc-icon nc-simple-remove"></i>
</button>
<div class="message"><i class="nc-icon nc-bell-55"></i>
My alert message.
</div>
</div>
</div>
</div>
And I'm using this to trigger the alert to being opened:
$('.alert').show();
Share
Improve this question
asked Nov 2, 2017 at 3:17
John Von CollnJohn Von Colln
151 silver badge5 bronze badges
1
- What do you mean by "have another alert without reloading the page"? Do you want to write a function to hide and show alerts? – Harsha Jayamanna Commented Nov 2, 2017 at 3:53
4 Answers
Reset to default 6You simply have to add an on listener to overwrite the default behaviour. This worked for me:
$(".alert").on("close.bs.alert", function () {
$alertMsg.hide();
return false;
});
This solution was provided by Winifred Cadap on his blog. You can find it here.
Try this
$(".alert").alert('close');
To hide just use $('.alert').hide();
Check the below example
$('.alert').show();
setTimeout(function(){ $('.alert').hide(); }, 3000);
<script src="https://code.jquery./jquery-3.2.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn./bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn./bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<div style="display: none;" class="alert alert-danger alert-with-icon" data-notify="container">
<div class="container">
<div class="alert-wrapper">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<i class="nc-icon nc-simple-remove"></i>
</button>
<div class="message"><i class="nc-icon nc-bell-55"></i>
My alert message.
</div>
</div>
</div>
</div>
Easy way is to dismiss an alert inline. for that add .alert-dismissible
class to your alert box
<div style="display: none;" class="alert alert-danger alert-with-icon alert-dismissible fade show" data-notify="container" role="alert">
<div class="container">
<div class="alert-wrapper">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<i class="nc-icon nc-simple-remove"></i>
</button>
<div class="message"><i class="nc-icon nc-bell-55"></i>
My alert message.
</div>
</div>
</div>
</div>
i modified your code. now data-dismiss="alert"
attribute in your button trigger the javaScript functionality. i also added fade show
class which gives a smooth animation.
i don't understand what you mean by
hide an alert so that we can have another alert without reloading the page?
本文标签: javascriptBootstrap 4 hide not close alertsStack Overflow
版权声明:本文标题:javascript - Bootstrap 4 hide not close alerts - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745422669a2657971.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论