title: Resuming default behaviour after preventDefault()
body: <p>I've written a small jQuery plugin which is designed to ask the question, "Are you sure?" when clicking on a link or submitting a form.</p>
  
  <p>It's used like this:</p>
  
  <pre><code>&lt;a href="link.php" class="confirm"&gt;Link&lt;/a&gt;
  </code></pre>
  
  <p>Or like this:</p>
  
  <pre><code>&lt;form action="link.php" method="post"&gt;
      &lt;button class="confirm"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>What I am doing is using preventDefault() to prevent the default behavior when the anchor or button is clicked.  I then display a confirm dialogue where the user has to click either OK or Cancel.</p>
  
  <p>If the user clicks Cancel then nothing happens (as expected).</p>
  
  <p>However, if the user clicks OK I am firing the click event again, and using a flag that was set first time around to not prevent the default behaviour second time around (I'm instead returning true). Except that it's not working.  Clicking either OK or Cancel in the confirm dialogue doesn't do anything.</p>
  
  <p>The plugin is below:</p>
  
  <pre><code>(function($) {
  
      $.fn.fw_confirm = function(options) {
  
          // Flag to check for the first click event
          var paused = false;
  
          return this.on("click", function(e) {
  
              // The anchor or the button that was clicked
              var button = $(this);
  
              // If this is the second click event, the user must have confirmed so return true
              if (paused == true) {
  
                  // Reset the flag
                  paused = false;
  
                  // This isn't working, or at least it's not submitting the form or proceeding to the URL of the hyperlink when I would expect it to
                  return true;
              }
  
              // First time around prevent the default behavior
              e.preventDefault();
              e.stopImmediatePropagation();
  
              // Set the flag to true, ready for the second click event
              paused = true;
  
              if (confirm("Are you sure?")) {
                  // The user is certain, so trigger the click event again
                  return button.trigger("click");
              } else {
                  // The user cancelled, reset the flag
                  paused = false;
                  return;
              }
          });
      }
  })(jQuery);
  </code></pre>