javascript - Navigation Menu not rendering in browser -
i made navigation menu website used when people access site on phone. reason, can see working on fiddle made, not when test in browser.
i've tested chrome, , latest version of ie, don't see responsive navigation menu made when shrink browser's size.
this javascript file looks like:
$("#nav").addclass("js").before('<div id="menu">☰ menu </div>'); $("#menu").click(function(){ $("#nav").toggle(); }); $(window).resize(function(){ if(window.innerwidth > 768){ $("#nav").removeattr("style"); } }); here fiddle:
and css file , html file have same code in fiddle. thing different have css file rest of site. css file navigation menu. tried importing css file navigation menu main css file, didn't work either.
i appreciate advice on fixing issue. said, works in fiddle, not in browser. in advance.
you should run code when dom ready or #nav parsed browser, or jquery cannot find #nav. may have 2 alternative ways:
run code when dom ready like:
$(function() { $("#nav").addclass("js").before('<div id="menu">☰ menu </div>'); $("#menu").click(function(){ $("#nav").toggle(); }); $(window).resize(function(){ if(window.innerwidth > 768){ $("#nav").removeattr("style"); } }); });put js code @ bottom of html.
why jsfiddle works?
that's because jsfiddle wrap js code $(window).load below if use jquery:
$(window).load(function(){ $("#nav").addclass("js").before('<div id="menu">☰ menu </div>'); ... });
Comments
Post a Comment