Display modal dialog with jquery ui without element?

I am making a small jquery application. I need a confirmation window. However, I do not want to add an element to the body so that I can open the dialog box. Is there any way to avoid this? To just bring up a dialog and pass arguments like title, text and parameters?

+6
source share
2 answers

When creating the jQuery UI dialog box, the current versions (1.8. *) Automatically add the dialog to the body.

So, if you do:

$('<div>').dialog({modal: true}) 

It just works. You have to make sure that you call .remove() when the dialog is closed to remove the new item though!

 function myalert(title, text) { var div = $('<div>').html(text).dialog({ title: title, modal: true, close: function() { $(this).dialog('destroy').remove(); }, buttons: [{ text: "Ok", click: function() { $(this).dialog("close"); }}] }) }; myalert("Test", "This is a test modal dialog"); 

See http://jsfiddle.net/alnitak/G3GRZ/ for a full working demo.

+14
source

Just do it:

 $('<div>My dialog text.</div>').dialog({ modal: true }); 
+4
source

Source: https://habr.com/ru/post/887572/


All Articles