Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  176] [ 1]  / answers: 1 / hits: 31512  / 9 Years ago, mon, september 21, 2015, 12:00:00

Let's say I've the following piece of code:



<div class=alert alert-info fade in id=bsalert>
<a href=# class=close data-dismiss=alert aria-label=close>&times;</a>
<strong>Info!</strong> This alert box could indicate a neutral informative or action
</div>


How can I activate it manualy by using jQuery?


More From » jquery

 Answers
11

Bootstrap uses the in and out class for visibility. You just need to toggle those classes. Also, if you want to keep the alert around once cancelled you can add a return false to the close.bs.alert event.





function toggleAlert(){
$(.alert).toggleClass('in out');
return false; // Keep close.bs.alert event from removing from DOM
}


$(#btn).on(click, toggleAlert);
$('#bsalert').on('close.bs.alert', toggleAlert)

<link rel=stylesheet type=text/css  href=https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css>
<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<script src=https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js></script>
<button id=btn>Toggle</button>

<div class=alert alert-info fade out id=bsalert>
<a href=# class=close data-dismiss=alert aria-label=close>&times;</a>
<strong>Info!</strong> This alert box could indicate a neutral informative or action
</div>

<div>
content




[#64974] Saturday, September 19, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
siena

Total Points: 199
Total Questions: 91
Total Answers: 91

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;