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 wa
FWIW I created a JavaScript class that can be used at run-time.
It's over on GitHub, here.
There is a readme there with a more in-depth explanation, but I'll do a quick example below:
var ba = new BootstrapAlert();
ba.addP("Some content here");
$("body").append(ba.render());
The above would create a simple primary alert with a paragraph element inside containing the text "Some content here".
There are also options that can be set on initialisation.
For your requirement you'd do:
var ba = new BootstrapAlert({
dismissible: true,
background: 'warning'
});
ba.addP("Invalid Credentials");
$("body").append(ba.render());
The render method will return an HTML element, which can then be inserted into the DOM. In this case, we append it to the bottom of the body tag.
This is a work in progress library, but it still is in a very good working order.