Search code examples
javascriptjqueryjquery-uialertjquery-ui-dialog

jQuery UI Alert Dialog as a replacement for alert()


I'm using alert() to output my validation errors back to the user as my design does not make provision for anything else, but I would rather use jQuery UI dialog as the alert dialog box for my message.

Since errors are not contained in a (html) div, I am not sure how to go about doing this. Normally you would assign the dialog() to a div say $("#divName").dialog() but I more need a js function something like alert_dialog("Custom message here") or something similiar.

Any ideas?


Solution

  • I don't think you even need to attach it to the DOM, this seems to work for me:

    $("<div>Test message</div>").dialog();
    

    Here's a JS fiddle:

    http://jsfiddle.net/TpTNL/98