I am using JQuery dialog in my scenario. $(selector).dialog("close");
does not work. What is an alternative do I have in order to close JQuery dialog?

- 25,747
- 28
- 93
- 153

- 5,502
- 14
- 58
- 89
4 Answers
try $('#dialog').dialog('destroy');
where #dialog is the id of the div tag you display in the dialog

- 5,117
- 1
- 19
- 26
You can use:
$('#dialogId').dialog('destroy');
BUT it is very strange, that .dialog('close')
doesn't work. Can you provide more information?

- 25,747
- 28
- 93
- 153
have you checked out this question.? have a look..
jQuery UI Dialog Box - does not open after being closed
Thanks.

- 1
- 1

- 3,808
- 1
- 24
- 48
As per the previous answers, dialog('destroy') is used when you need to completely remove the element and its contents. If you just need to hide or close and retain the values you just need to hide the element. $("#dialog").hide();
But yes, if you do not destroy, it will keep on adding the dialog in the DOM which you should avoid, for that put a validation if the dialog is not undefined before initializing the dialog again so that if it exists, just say $("#dialog").show();
or $("#dialog").dialog('open');
$("#dialog").dialog({
title: "xyz",
modal: true,
close: function(){
$("#dialog").hide()
//This is where the code reaches when you press the x button or click on the custom cancel or close button.
}
});
$("#dialog").open();
Hope it answers the question.

- 221
- 1
- 2
- 8