title: How to reset jquery dialog timeout for next dialog?
body: <p>I have an add-to-bag button used throughout our site and we want a dynamic popup to appear to acknowledge what was just added, and then it goes away. I'm finding that if you click another add button, it has the previous dialog's timeout attached. To fix this so the next dialog has its own 10,000 setTimeout rather than whatever is left over from the last one I have come up with the following code (that doesn't do the trick).</p>
  
  <pre><code>$(document).ready(function ()
  {
      // Create object for future dialog box - so it's available to the close method
      var addToBagDialogVar = $('&lt;div id="addToBagDialogBox"&gt;&lt;/div&gt;');
      var autoCloseTimeout = 10000;
      var dialogTimer;
  
      $(".addToBagPU").click(function (e)
      {
          var result = "";
          $.get(this.href, function (data) { SetData(addToBagDialogVar, data); });
          return false;
      });
  
      // Start listening for the close link click
      $(document).on("click", "#bagPUCloseLink", function (event)
      {
          event.preventDefault();
          CloseDialog(addToBagDialogVar);
      });
  
      function SetData(addToBagDialogVar, data)
      {
          result = data;
          var regex = data.match("{{(.*)}}");
          var bagCount = regex[1];
  
          addToBagDialogVar.html(result).dialog({
              open: function ()
              {
                  clearTimeout(dialogTimer);
                  $(".ui-dialog-titlebar-close").hide();
                  SetBagCount(bagCount),
                  dialogTimer = setTimeout(function () { CloseDialog(addToBagDialogVar); }, autoCloseTimeout);
              },
              show: { effect: "fadeIn", duration: 800 },
              close: function () { clearTimeout(dialogTimer); },
              width: 320
          });
      }
  
      function CloseDialog(closeThisDialog)
      {
          closeThisDialog.dialog("close");
          closeThisDialog.dialog("destroy").remove();
      }
  });
  </code></pre>
  
  <p>The dialog is loaded with dynamic content from an external .Net page with product data and has a close link inside that page, which is why the dialog is loaded into <strong>addToBagDialogVar</strong> so it's available to <strong>CloseDialog</strong>.</p>
  
  <p>All of that works just fine. It's just the reset of the timer that doesn't appear to be happening. If I go down a page of products and add each one to my bag, the 3rd or 4th dialog is only up for a second or so because they have all been using the first dialogs setTimeout.</p>
  
  <p>I've read and read and tried too many different ways to remember and now my brain is mush.</p>