title: Trying to set jquery to fire once after resizing
body: <p>Is there a way to fire jquery only once when resizing? I have here a script that adds a <code>hash(#)</code> within the <code>href</code> of an <code>anchor &lt;a&gt;</code> element. The problem is the script keeps when resizing and so it keeps adding <code>hash</code> within the <code>href</code>. Is there a way to make it fire only once?</p>
  
  <pre><code>(function($){
      'use strict';
  
  
  
      var mobileMenuDrawer = {
  
          init : function() {
  
              $('.region-primary-menu').addClass('primary-mobile-menu');
              $('.primary-mobile-menu .menu.-primary &gt; .menu-item').addClass('mobile-menu-item');
              $('.primary-mobile-menu .menu.-primary &gt; .mobile-menu-item &gt; .link').off('click').on('click', function() {
                  $(this).closest('.mobile-menu-item').toggleClass('-active');
              })
          },
  
          clear : function() {
              $('.primary-mobile-menu, .mobile-menu-item').removeClass('primary-mobile-menu mobile-menu-item');
          }
      }
  
      var addHash = {
  
          init : function() {
  
              if ($('.region-primary-menu').hasClass('primary-mobile-menu')) {
  
                  $('.primary-mobile-menu .mobile-menu-item &gt; .link').each(function() {
                      // console.log($(this).attr('href'));
                      let currentUrl = $(this).attr('href');
  
                      $(this).prop('href', '#' + currentUrl);
  
                      // this.href = '/#/' + this.href;
                      // window.location.hash     = $(this).attr('href');
                  });
              }
  
              else {
  
                  $('.primary-mobile-menu .mobile-menu-item &gt; .link').each(function() {
  
                      $(this).removeAttr('#');
  
                  });
  
              }
          }
      }
  
  
      $(document).ready(function() {
  
          if ($(window).outerWidth() &lt;= 1024) {
              mobileMenuDrawer.init();
          }
  
          else {
              mobileMenuDrawer.clear();
          }
  
          addHash.init();
  
  
      });
  
      $(window).on('resize', function() {
  
          if ($(window).outerWidth() &lt;= 1024) {
              mobileMenuDrawer.init();
              addHash.init();
          }
  
          else {
              mobileMenuDrawer.clear();
          }
      });
  
  
  
  })(jQuery)
  </code></pre>