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

4

5

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.

Approve answered 19/9, 2011 at 11:44 Comment(4)
why don't you call this statement before calling the opening code of the new dialog?Antitype
I called it before call the new window. But it close new window too,this is only my problemApprove
Do you have any details on the dialog being opened? You could use the css :not() selector.Randee
sorry it works,but new dialog goes to bottom.Approve
B
10

Try:

$(".ui-dialog-content").not(<selector for the dialog you don't want to close>).dialog("close");
Bunchy answered 19/9, 2011 at 11:50 Comment(0)
L
4

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");
Lilylivered answered 30/1, 2012 at 8:2 Comment(1)
This seems like the best solution to me - it is necessary NOT to close the non-visible jQuery dialogs, because these may not have yet been initialized (which results in an error in my case).Exerciser
L
1

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");
Laconic answered 20/12, 2021 at 18:10 Comment(0)
S
0

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.

Subconscious answered 19/9, 2011 at 11:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.