w3father
w3father

Reputation: 569

How to close all jquery ui dialog before open a new dialog?

I want to close all jquery dialogs before open a new dialog.

I'm trying with following code.

$(".ui-dialog-content").dialog("close");

It works but it too close new dialog too.

please help me anyone.

Upvotes: 5

Views: 9953

Answers (4)

user2794804
user2794804

Reputation: 59

Following on from Chris's solution, you can do the same without adding your own custom class with:

$(".ui-dialog:visible").find(".ui-dialog-content").dialog("close");

Upvotes: 1

chris
chris

Reputation: 505

Just ran into this myself. I solved it like this. .dialog is a class that all the elements I made into dialogs share.

$(".ui-dialog:visible").find(".dialog").dialog("close");

Upvotes: 4

Tim B James
Tim B James

Reputation: 20364

How are you opening the new Dialog? You must be opening each dialog using it's own code, e.g.

$('#dialog1').dialog();
$('#dialog2').dialog();

etc... in order to open each individually?

Just give them all a class name class="opened-dialogs" then call $('.opened-dialogs').dialog("close"); before then opening the new one.

Upvotes: 0

cicloon
cicloon

Reputation: 1099

Try:

$(".ui-dialog-content").not(<selector for the dialog you don't want to close>).dialog("close");

Upvotes: 10

Related Questions