leora leora - 5 months ago 33
jQuery Question

How can I tell if a jquery ui dialog query has been initialized?

I have the following code to detect if a jquery ui dialog is open:

if ($("#dialog-myDialog").dialog("isOpen")) {
return;
}


which works fine but I found a situation where this code get called prior to the dialog being initialized in the first place and this if statement seems to just blow up in this case.

What is the best way to check if a jquery ui dialog has been initialized so I can properly handle this situation.

Answer

Test whether the element has the ui-dialog-content class:

if ($("#dialog-myDialog").hasClass("ui-dialog-content") &&
    $("#dialog-myDialog").dialog("isOpen")) {
    return;
}
Comments