Matthew Rygiel
Matthew Rygiel

Reputation: 1257

Closing all jquery dialog windows in JavaScript

How does one close all jquery ui dialog windows in javascript?

Situation:

The page has multiple things that can be opened using the dialog boxes. I need a way to close all previous windows before opening a new one.

Upvotes: 40

Views: 22885

Answers (2)

user3899909
user3899909

Reputation: 21

Be careful with the above. If you define a close method for your dialog, it will get fired even if the dialog is not open. This was a huge issue in an Angular project where we were manually calling $apply() in our dialog close method. Another event was trying to close all dialogs on the screen and our close method was called even though wasn't open resulting in a digest issue.

Upvotes: 2

Nick Craver
Nick Craver

Reputation: 630429

They all have the .ui-dialog-content class, so select by that and close them, like this:

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

Upvotes: 94

Related Questions