title: jQuery: addClass only once
body: <p>I have an <code>addClass</code> and <code>removeClass</code> function running on window resize, using an if else statement. The markup is as follows:</p>
  
  <pre><code>$(window).load(function() {
    resize();
  });
  
  //Every resize of window
  $(window).resize(function() {
    resize();
  });
  
  //Dynamically assign height
  function resize() {
    // Handler for .ready() called.
      var windowWidth = $(window).width(),
          windowHeight = $(window).height(),
          windowHeight = windowWidth / 1.7777;
  
          var loadwindowHeight = $(window).height(),
              loadspriteHeight = $('.spritespin-canvas').height();
  
              if(loadspriteHeight &lt; loadwindowHeight) {
                  $('.spritespin-canvas').addClass('height');
              } else {
                  $('.spritespin-canvas').removeClass('height');
              }
  
  }
  </code></pre>
  
  <p>The only problem is, when you resize the window, it keeps repeatedly adding and removing the class, it it possible to run the <code>addClass</code> and <code>removeClass</code> functions once? Any suggestions would be greatly appreciated!</p>