title: Dropdown hover enable/disable on window resize
body: <p>I'm wanting the dropdown to open on hover, only if the window is larger than 767px. I'm trying to call a function on page load and on window resize with the a width size condition. The enableHover() function only works on page load and not on window resize.</p>
  
  <p><a href="https://codepen.io/gabe1331/pen/mBjXNZ" rel="nofollow noreferrer">codepen</a></p>
  
  <pre><code>&lt;nav class="navbar navbar-expand-lg navbar-light bg-light"&gt;
    &lt;a class="navbar-brand" href="#"&gt;navbar&lt;/a&gt;
    &lt;button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation"&gt;
      &lt;span class="navbar-toggler-icon"&gt;&lt;/span&gt;
    &lt;/button&gt;
    &lt;div class="collapse navbar-collapse" id="navbarNavDropdown"&gt;
      &lt;ul class="navbar-nav"&gt;
        &lt;li class="nav-item"&gt;
          &lt;a class="nav-link" href="#"&gt;Home &lt;span class="sr-only"&gt;(current)&lt;/span&gt;&lt;/a&gt;
        &lt;/li&gt;
        &lt;li class="nav-item"&gt;
          &lt;a class="nav-link" href="#"&gt;link&lt;/a&gt;
        &lt;/li&gt;
        &lt;li class="nav-item"&gt;
          &lt;a class="nav-link" href="#"&gt;link&lt;/a&gt;
        &lt;/li&gt;
        &lt;li class="nav-item dropdown"&gt;
          &lt;a class="nav-link dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;
            Dropdown
          &lt;/a&gt;
          &lt;div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink"&gt;
            &lt;a class="dropdown-item" href="#"&gt;dropdown link&lt;/a&gt;
            &lt;a class="dropdown-item" href="#"&gt;dropdown link&lt;/a&gt;
            &lt;a class="dropdown-item" href="#"&gt;dropdown link&lt;/a&gt;
          &lt;/div&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/nav&gt;
  </code></pre>
  
  <pre><code>jQuery(document).ready(function($) {
      //call dropdown hover and on load &amp; resize
      $( window ).resize(function() {
          enableHover();
      });
      enableHover();
  });
  
  //emable hover when window &gt; 767px 
  function enableHover() {
     if ($(window).width() &gt; 767) {
        $('nav.navbar li.dropdown').hover(function() {
           $(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn(500);
         }, function() {
           $(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut(500);
           });
         }
      }
  </code></pre>