Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Alert Box with Foundation

How should I go about adding a new alert box dynamically to a page with foundation? It looks like I would have to insert the html markup for the box and then reinitialize foundation for the whole page... that can't be right, can it?

Is there some easy method for adding an alert box dynamically?

I would expect an api such as: $("#myElement").foundation('alert', "foo 123");

Example:

$.post("/some/url", {some:'data'})
    .fail(function(){
        $("#myElement").foundation('alert', 'Process failed!');
    });
like image 764
Joe Flateau Avatar asked Feb 10 '14 15:02

Joe Flateau


1 Answers

No API but you can do something like this:

$.post("/some/url", {some:'data'})
.fail(function(){
    var alertBox = '<div data-alert class="alert-box"> Sorry, the request failed.  <a href="#" class="close">&times;</a></div>';
    $("#errorArea").append(alertBox).foundation();
});
like image 179
phillyslick Avatar answered Sep 19 '22 08:09

phillyslick