title: remove /add class on window resize jquery
body: <p>I'm trying to use the following code to remove a class on window resize for a menu in a responsive theme, but it won't work.</p>
  
  <pre><code> (function() {
  var $window = $(window),
      $ul = $('ul.nav');
  
  $window.resize(function(){
      if ($window.width() &lt; 979) {
          return $ul.addClass('float');
      }else{
  
      $ul.removeClass('float')};
  }).trigger('resize');
  });
  </code></pre>
  
  <p>The .float isn't defined with the .css. It's just there if the submenu (generated dynamically in an admin area) get too large to fit in the container.</p>
  
  <p>Here's the code for generating the "float-effect" when the submenu is to large</p>
  
  <pre><code>   $('.float &gt; li.dropdown &gt; a + ul').each(function(index, element) {
    // IE6 &amp; IE7 Fixes
    if ($.browser.msie &amp;&amp; ($.browser.version == 7 || $.browser.version == 6)) {
    var category = $(element).find('a');
    var columns = $(element).find('ul').length;
  
    $(element).css('width', (columns * 143) + 'px');
  $(element).find('ul').css('float', 'left');
      }       
  
      var menu = $('.float').offset();
      var dropdown = $(this).parent().offset();
  
      i = (dropdown.left + $(this).outerWidth()) - (menu.left +      $('.float').outerWidth());
  
      if (i &gt; 0) {
          $(this).css('margin-left', '-' + (i + 5) + 'px');
      }
  });
  </code></pre>
  
  <p>Here's a part of the beginning of the menu code</p>
  
  <pre><code>    &lt;?php if ($categories) { ?&gt;
      &lt;div class="menu"&gt;
  &lt;ul class="nav float"&gt;
  &lt;?php foreach ($categories as $category) { ?&gt;
  &lt;li class="dropdown"&gt;&lt;a href="&lt;?php echo $category['href']; ?&gt;"&gt;
      &lt;?php echo $category['name']; ?&gt;&lt;/a&gt;
       .
       .
       .
       .
       ecc.
  </code></pre>
  
  <p>Any other ideas to remove/ add the class ".float" on window resizing?
  Thanks in advance for any tip.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>After trying a little bit, i've found an alternative solution with the .css query</p>
  
  <pre><code>  @media (max-width: 979px) 
  </code></pre>
  
  <p>Now it's working, but i still can't understand why the jQuery resize isn't working.</p>