problem with calling dialog('close') on a button within the dialog

problem with calling dialog('close') on a button within the dialog

Hello,

I have a dialog with an anchor tag inside of it that I want to use to run some jquery when the user clicks on it. Specifically, I want to close the dialog and show a popup for a few seconds letting the user know that their password was reset.  The dialog looks like this:

  1. <div data-role="page" data-dialog="true" id="page-reset-password">
  2.       ***content here***      
  3.       <a href="#" id="btn-reset-password" class="ui=btn">Reset Password</a>
  4. </div>

I can't seem to figure out the correct event to bind the 'click' event to so that the click event doesn't register until the dialog is initiated.  For instance, I have tried the js below:

  1. $(function() {
  2.       $("#page-reset-password").on("pagecreate", function() {
  3.             $("#btn-reset-password").on("click", function() {
  4.                   $("#page-reset-password").dialog("close");
  5.             });
  6.       });
  7. });

No matter what i try, i get the following error: Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'

Would anybody be able to tell me what I am doing wrong here?  thank you very much in advance for any advice that you can provide.