Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Undelegate does not work
    primarykey
    data
    text
    <p>I'm creating a responsive template and I want to remove the listeners on an element when screen is being resized or is smaller than the specified width.<br /> Imagine an menu which when you hover on it's items, it shows you the sub-menus in normal displays but the same menu in mobile devices will show the sub-menus only by tapping or clicking on the items.</p> <p>I can't make the undelegate work. In resized screen I still have the <code>mouseover</code> and <code>mouseout</code> event-listeners. I'm not getting any errors in console and I've tried both:</p> <ul> <li><code>.off('mouseover', 'li')</code></li> <li><code>.off('mouseover')</code></li> <li><code>.undelegate('li', 'mouseover')</code></li> <li><code>.undelegate('li')</code></li> </ul> <p><br />and none of them works.</p> <pre><code>var $window = $(window); function handleSidenav() { $(".nav-list").delegate('li', 'mouseover', function(e) { $(this).find("a").addClass('active'); $(this).find("div.sub-items").toggle(); }).delegate('li', 'mouseout', function(e) { $(this).find('a').removeClass('active'); $(this).find("div.sub-items").toggle(); }); } function checkWidth() { var windowsize = $window.width(); if (windowsize &lt; 767) { smallScreenDelegation(); } else { SmallScreenUndelegation(); } } checkWidth(); handleSidenav(); $window.resize(checkWidth()); function smallScreenDelegation() { $(".nav-list").undelegate('li'); //It's not working $(".nav-list").undelegate('li'); //It's not working $(".nav-list").delegate('li a:first', 'click', function(event) { if ($(this).next().is(':hidden')) { $(this).addClass('active'); $(this).next().slideDown('slow'); } else { $(this).removeClass('active').next().slideUp('slow'); } event.preventDefault(); }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload