0

I create a jQuery dialog in the usual way, $('#MyDlg').dialog(...), and display it. In some other function I want to close it, so I do $('#MyDlg').dialog('close'), but nothing happens.

After some testing I found that if I save the object reference from dialog creation, make it available to the other function, and call dialog('close') on it, the dialog does close as expected.

Isn't is supposed to work the way I tried first? Or am I missing something?

2
  • 2
    Your first snippet is supposed to work. Do you perchance have more than one element with a MyDlg id attribute? Commented Apr 29, 2014 at 15:21
  • Aha! You're right! The problem is that the dialog DIV is rebuilt in the original DOM location by an Ajax call, so the other function picks up that "un-dialogified" DIV rather than the first one. I'll have to rethink my logic/layout... Thanks! Commented Apr 29, 2014 at 15:27

1 Answer 1

1

I was pointed in the right direction by Frédéric Hamidis comment. The dialog DIV is rebuilt in the original DOM location by an Ajax call, so the other function picks up that "un-dialogified" DIV rather than the first one. I end up with a DOM containing two DIVs with the same id. Not good.

I will relocate the dialog div to a part of the layout that does not get rebuilt.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.