title: how to prevent further jquery script after confirm-cancel
body: <p>I have a script that opens a confirm box when clicking on a link :</p>
  <p>html :</p>
  <pre><code>&lt;a href=&quot;validation/object_1/&quot; class=&quot;validation&quot;&gt;Validate&lt;/a&gt;
  &lt;a href=&quot;validation/object_2/&quot; class=&quot;validation&quot;&gt;Validate&lt;/a&gt;
  </code></pre>
  <p>jquery</p>
  <pre><code>$('.validation').on('click', function() {
    return confirm('Are you sure tou want to validate this ' + $(this).attr('href').split(&quot;/&quot;)[1] + ' ?');
  });
  </code></pre>
  <p>I have another jquery script which loads a waiting animation (a quite complex script that I have not coded myself and is included in my Content Management System application)</p>
  <p>When I click on the link, the confirm pop up opens and when I click on &quot;Cancel&quot;, I don't want the waiting animation to be run.</p>
  <p>how can I prevent any further jquery script to be run after I click on Cancel ?</p>
  <p><strong>edit</strong> : here is the full script, with loading animation :</p>
  <pre><code>    (function($) {
          
          $('.validation').on('click', function() {
    return confirm('Are you sure tou want to validate this ' + $(this).attr('href').split(&quot;/&quot;)[1] + ' ?');
  });
      
      /**
         * Represents the loading animation.
         */
        Loadinganimation = function(context, settings) {
          this.settings = settings;
          this._init = function(context) {
            // Exclude subselectors.
            if (settings.subselector != '') {
              var subselectorSuffix = ' ' + settings.subselector;
            } else {
              var subselectorSuffix = '';
            }
            // Show on href click!
            if (Drupal.settings.jquery_loadinganimation.show_on_href) {
              // Exclude some further cases that shell not trigger.
              $(context)
                  .find(&quot;a[href]&quot; + settings.subselector)
                  .not('a[href*=&quot;javascript:&quot;]')
                  .not('a[href^=&quot;#&quot;]')
                  //.not('a[target=&quot;_blank&quot;]')
                  .not(&quot;.validation&quot;)
              .not('a[href^=&quot;http://fakepath&quot;]')
                  .not(&quot;.noLoadingAnimation&quot;)
              .not(&quot;.views-submit-button&quot;)
                  .each(
                      function(i, element) {
                        // Only trigger links that have no js events registered.
                        if (typeof $(this).data(&quot;events&quot;) == 'undefined'
                            || jQuery.isEmptyObject($(this).data(&quot;events&quot;))) {
                          $(this)
                              .click(
                                  function(eventObject) {
                                    // Nicht bei Öffnen in neuem Tab (Strg+Klick)
                                    if (!eventObject.ctrlKey) {
                                      Drupal.behaviors.jquery_loadinganimation.Loadinganimation
                                          .show();
                                    }
                                  });
                        }
                      });
            }
      
            // Show on form submit
            if (Drupal.settings.jquery_loadinganimation.show_on_form_submit) {
              // Only execute if no other js events are registered to prevent cases
              // where page is not being reloaded and layer does not close though.
              $(context).find(&quot;form&quot; + subselectorSuffix).not(&quot;.noLoadingAnimation&quot;).not(&quot;.views-submit-button&quot;).not(&quot;.validation&quot;).submit(function() {
                Drupal.behaviors.jquery_loadinganimation.Loadinganimation.show();
                $(context).ajaxStop(function() {
                  // Hide loading animation after ALL ajax events have finished
                  Drupal.behaviors.jquery_loadinganimation.Loadinganimation.hide();
                });
              });
            }
      
            // Show on AJAX
            if (context == document) {
              // Global context!
              if (Drupal.settings.jquery_loadinganimation.show_on_ajax) {
                // Register loading animations for ajax events!
                $(context).ajaxStart(function() {
                  // Show loading animation on request.
                  Drupal.behaviors.jquery_loadinganimation.Loadinganimation.show();
                });
      
                $(context).ajaxStop(function() {
                  // Hide loading animation after finish.
                  Drupal.behaviors.jquery_loadinganimation.Loadinganimation.hide();
                });
              }
            }
      
            // Hide on animation click!
            if (Drupal.settings.jquery_loadinganimation.close_on_click) {
              $(&quot;div#loadinganimation&quot;).on('click', function() {
                Drupal.behaviors.jquery_loadinganimation.Loadinganimation.hide();
              });
            }
      
            // Hide on ESC press.
            if (Drupal.settings.jquery_loadinganimation.close_on_esc) {
              $(document).keyup(function(event) {
                var keycode = event.which;
                if (keycode == 27) { // escape, close box
                  Drupal.behaviors.jquery_loadinganimation.Loadinganimation.hide();
                }
              });
            }
          };
      
          // Initialize!
          this._init(context);
      
          // Register global Drupal.behaviors.jquery_loadinganimation.Loadinganimation
          // object after init!
          Drupal.behaviors.jquery_loadinganimation.Loadinganimation = this;
      
          /**
           * Displays the loading animation.
           */
          this.show = function() {
            // Only show if not already shown.
            if ($(&quot;div#loadinganimation&quot;).length == 0) {
              $(&quot;body&quot;)
                  .append(
                      '&lt;div id=&quot;loadinganimation&quot;&gt;&lt;div class=&quot;loadinganimation-box&quot;&gt;&lt;div class=&quot;loadinganimation-outer&quot;&gt;&lt;div class=&quot;loadinganimation-inner&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;span class=&quot;loading-text&quot;&gt;'+ Drupal.t('Merci de patienter ...', {}, {context: &quot;jquery_loadinganimation&quot;}) +'&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;');
            }
          };
      
          /**
           * Hides the loading animation.
           */
          this.hide = function() {
            $(&quot;div#loadinganimation&quot;).remove();
          };
        };
      
        /**
         * Initialization
         */
        Drupal.behaviors.jquery_loadinganimation = {
          /**
           * Run Drupal module JS initialization.
           *
           * @param context
           * @param settings
           */
          attach : function(context, settings) {
            // Initialize general loading animation.
            Drupal.behaviors.jquery_loadinganimation.Loadinganimation = new Loadinganimation(
                context, settings.jquery_loadinganimation);
          }
        };
        
        
      })(jQuery);
  </code></pre>