dmhall0 Posted July 20, 2012 Share Posted July 20, 2012 I am using the jQuery toggle function to display a menu when the user clicks on an image. The menu starts off hidden but when I click on the image it appears correctly, lasts less than 1 second, and then hides again. Here is my js/jquery code: <script type="text/javascript" src="'.base_url().'assets/jquery/js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="'.base_url().'assets/jquery/js/jquery-ui-1.8.21.custom.min.js"></script> <script type="text/javascript"> $("document").ready(function() { $("#user_menu").hide(); $("a.menu_title").click(function() { $("#user_menu").toggle(); }); });</script> Any ideas why this is happening? Thanks! Link to comment https://forums.phpfreaks.com/topic/265995-jquery-toggle-doesnt-stay-down/ Share on other sites More sharing options...
dmhall0 Posted July 20, 2012 Author Share Posted July 20, 2012 Nevermind... I figured it out. Stupid mistake on my part. I set the image as a link and had href="" so it was reloading the page, thus show then hide again when the page would reload. Link to comment https://forums.phpfreaks.com/topic/265995-jquery-toggle-doesnt-stay-down/#findComment-1363076 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 You can avoid this by using preventDefault http://api.jquery.com/event.preventDefault/ Link to comment https://forums.phpfreaks.com/topic/265995-jquery-toggle-doesnt-stay-down/#findComment-1363083 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.