I am creating a user information editing dialog box that retrieves the editing information using $.post , but I cannot close this dialog because the dialog was not initialized using any HTML element.
I am trying $('#editUser').dialog('close') but this will not work.
Here is the main object:
<div id='userInfo'> <div class='user'> <span class='userId'>1</span> <span class='userName'>John</span> </div> <div class='user'> <span class='userId'>2</span> <span class='userName'>Jane</span> </div>
and here is the script used to create the dialog:
$(function() { $('.user').click(function() { var uid = $(this).find('span.userId').html(); $post('/e-val/user/edit.php', {id: uid}, function(html) { $(html).dialog(); }); }); $('body').on('click', '#closeEditDialog', function() { $('#editUser').dialog('close') }); });
The dialog opens as expected, but does not close as it should.
This is the HTML for the dialog returned by the ajax script.
<div id='editUser'> <table> <tr> <td>Username</td> <td><?php echo $user['name'] ?></td> </tr> <tr> <td>Email</td> <td><?php echo $user['email'] ?></td> </tr> <tr> <td colspan='2'> <input type='button' id='closeEditDialog' value='close' /> </td> </tr> </table> </div>
What can I do to close it? I can use $('#editUser').remove() Remove $('#editUser').remove() to remove the dialog, but I need to close it so as not to remove it.
user1590083
source share