setTimout and dialog.close with jquery after return message

setTimout and dialog.close with jquery after return message

I have an email submission modal and everything works fine. It grabs the data, PHP processes the data and sends an email and then gives the success message back to the script then the script display "thank you for submitting. blah blah blah."

After that I'm trying to use setTimeout to close that final message but it isn't working.

Here's the code that finishes the email submission:

  1. if (data.responseText !== ' ') {
  2.       $(#emailModal).text(data.responseText);
  3.       setTimeout(function(){ $('#emailModal').dialog('close')}, 5000);
  4. else {
  5.       $(#emailModal).text('Bad back end! Please try to send your message later.');
  6. }

Thank you for any help!