javascript - Jquery If / Else statement stopping preventdefault -


i have code mega navigation , need hover drop menu on desktop , click drop menu on mobile.

here snippet of code i'm having problems with:

if( $('js-full-menu').hasclass('js-touch-menu') ) {              (function(meganavtray){      menu.on('click', function(e){        e.preventdefault();          var wasopen = meganavtray.hasclass('is-active');        meganavtrays.find('.js-mega-nav-tray').removeclass('is-active');        if(!wasopen) {          meganavtray.addclass('is-active');          meganavtrays.addclass('is-active');        } else {          meganavtrays.removeclass('is-active');        }      });    })(meganavtray);    } else {      (function(meganavtray){        menu.hoverintent( function(){        meganavtray.addclass('is-active');        meganavtrays.addclass('is-active');          var wasopen = meganavtray.hasclass('is-active');          meganavtrays.find('.js-mega-nav-tray').removeclass('is-active');          if(wasopen) {          meganavtray.addclass('is-active');          meganavtrays.addclass('is-active');        } else {          meganavtray.removeclass('is-active');        }        });      })(meganavtray);      var fullnav = $('.js-full-menu');      fullnav.hoverintent( function() {}, function() {      $('.js-mega-nav-tray').removeclass('is-active');      meganavtrays.removeclass('is-active');    });    }    

basically problem if else statement removed leaving following code, preventdefault works fine. using full code above links direct pages instead of dropping meganav on click.

(function(meganavtray){    menu.on('click', function(e){      e.preventdefault();        var wasopen = meganavtray.hasclass('is-active');      meganavtrays.find('.js-mega-nav-tray').removeclass('is-active');      if(!wasopen) {        meganavtray.addclass('is-active');        meganavtrays.addclass('is-active');      } else {        meganavtrays.removeclass('is-active');      }    });  })(meganavtray);

any ideas why if / else stopping preventdefault working?

thanks in advance!

if( $('js-full-menu').hasclass('js-touch-menu') )

should

if( $('.js-full-menu').hasclass('js-touch-menu') )

you forgot . in class selector.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -