var ww = document.body.clientWidth; $(document).ready(function() { $(".toggleMenuCol").click(function(e) { e.preventDefault(); $(this).toggleClass("active"); $(".navCol").toggle(); }); setTimeout('adjustMenu2()',100); }) $(window).bind('resize orientationchange', function() { ww = document.body.clientWidth; adjustMenu2(); }); var adjustMenu2 = function() { ww = document.body.clientWidth; if (ww < 700) { $(".toggleMenuCol").css("display", "inline-block"); if (!$(".toggleMenuCol").hasClass("active")) { $(".navCol").hide(); } else { $(".navCol").show(); } $(".navCol li").unbind('mouseenter mouseleave'); $(".navCol li a.parent").unbind('click').bind('click', function(e) { // must be attached to anchor element to prevent bubbling e.preventDefault(); $(this).parent("li").toggleClass("hover"); }); } else if (ww >= 700) { $(".toggleMenuCol").css("display", "none"); $(".navCol").show(); $(".navCol li").removeClass("hover"); $(".navCol li a").unbind('click'); $(".navCol li").unbind('mouseenter mouseleave').bind('mouseenter mouseleave', function() { // must be attached to li so that mouseleave is not triggered when hover over submenu $(this).toggleClass('hover'); }); } }