I have this code for a side nav. How do I make the #menu disappear again when the #menu a is clicked? Thanks. function sideMenu() { $("#showmenu").click(function(e){ e.preventDefault(); $("#menu").toggleClass("show"); }); $("#menu a").click(function(event){ event.preventDefault(); if($(this).next('ul').length){ $(this).next().toggle('fast'); $(this).children('i:last-child').toggleClass('fa-caret-down fa-caret-left'); } }); }
Very hard to say without seeing the markup being manipulated by that scripting, and any educated guesses just mean more questions like: 1) If they're anchors, clicking on them should be taking you to another page "restoring" the state, so unless you're pissing away your accessibility with some poorly written non gracefuly degrading ajaxtardery... 2) If that's a normal side menu, or even one of the goofy "replace it with a useless icon for responsive" menus you shouldn't be throwing scripting at it for NOTHING. 3) Of course if you're using the bloated pile of garbage known as jQuery, you probably should be shoveling dirt on the site and start over. Basically I'd need to see a whole lot more of the page in question, but even your little snippet is throwing up major "don't do that" warning flags.
Thank you all for your help.. Im very new at javascript and jquery but I added this code which did the trick. $("#menu a.menu-link").click(function(e){ e.preventDefault(); $("#menu").toggleClass("show"); }); there are ways to shorten it probably but Im happy with it for now.