Sunday, May 12, 2024
98
rated 0 times [  99] [ 1]  / answers: 1 / hits: 168752  / 12 Years ago, tue, april 10, 2012, 12:00:00

I'm using Bootstrap 2.0 for my project and I would like to dynamically add Bootstrap alert box in my page (http://twitter.github.com/bootstrap/javascript.html#alerts). I want to do something like:



bootstrap-alert.warning(Invalid Credentials); 

More From » twitter-bootstrap

 Answers
963

Try this (see a working example of this code in jsfiddle: http://jsfiddle.net/periklis/7ATLS/1/)



<input type = button id = clickme value=Click me!/>
<div id = alert_placeholder></div>
<script>
bootstrap_alert = function() {}
bootstrap_alert.warning = function(message) {
$('#alert_placeholder').html('<div class=alert><a class=close data-dismiss=alert>×</a><span>'+message+'</span></div>')
}

$('#clickme').on('click', function() {
bootstrap_alert.warning('Your text goes here');
});
</script>​


EDIT: There are now libraries that simplify and streamline this process, such as bootbox.js


[#86348] Saturday, April 7, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leannjaidynd

Total Points: 111
Total Questions: 100
Total Answers: 94

Location: Slovenia
Member since Wed, Apr 6, 2022
2 Years ago
leannjaidynd questions
Thu, Mar 18, 21, 00:00, 3 Years ago
Sun, Jul 26, 20, 00:00, 4 Years ago
Mon, May 11, 20, 00:00, 4 Years ago
Tue, Feb 4, 20, 00:00, 4 Years ago
Mon, Sep 16, 19, 00:00, 5 Years ago
;