title: if ($(window).width() not working, ignores if condition on browser resize
body: <p>I have an (infamous) hamburger button that opens a dropdown on smaller devices. Since the slideToggle should only work on click if the viewport is less than 999px in width, my approach is the following:</p>
  
  <pre><code>$(document).ready(function () {
      if ($(window).width() &lt; 1000) {
          $("#mainNav a").click(function () {
              $("#mainNav").slideToggle(300);
          });
      }
  });
  </code></pre>
  
  <p>This actually works like a charm, however, when resizing the window, from under 1000px width to above, the slideToggle also affects the 'regular desktop menu'. </p>
  
  <p>I assume that I am using the wrong listener and already tried </p>
  
  <pre><code>$( window ).resize(function() {
  </code></pre>
  
  <p>but cannot make it work. I am pretty sure that the answer is near. Thanks in advance!</p>