47 posts
  • Author Level 1
  • Collector Level 3
  • United Kingdom
  • Exclusive Author
+1 more
Renny
says

Im having trouble making it so once a link in the nav has been clicked it closes the menu (yes i know there are scripts out there that can do it all, and bootstrap has it all) but i just want a simple little script that does two things.

I managed to do it once before but ive since lost my snippet due to my computer failing and saldy it isnt in my dropbox.

jQuery(document).ready(function($) { $(".ToggleMenu").click(function() { $("nav").slideToggle(500); }); });

Never been good with jquery, could anyone help me?

thank you in advance Tom

1368 posts
  • Weekly Top Seller
  • 5 Years of Membership
  • Author Level 6
  • Beta Tester
+5 more
Smartik
says

Show the HTML source as well. Or better create a Fiddle. :)

1127 posts
  • United Kingdom
  • Author Level 5
  • Affiliate Level 3
  • Collector Level 1
+5 more
Alexlasek
says

there is no way to help you, if we can’t see the code. Upload that bit into http://codepen.io/ with html and css then I will help you, otherwise it’s nearly impossible ;/

cheers

47 posts
  • Author Level 1
  • Collector Level 3
  • United Kingdom
  • Exclusive Author
+1 more
Renny
says

I’m sorry, I thought id put all the relevant coded needed.

http://jsfiddle.net/rG92z/

Ignore the fact the button to open jumps down in the fiddle. The problem im having is getting the menu to close once a menu link has been clicked on

Tom

1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
Gareth_Gillman
says

Hi Renny

hows this look? jsfiddle.net/rG92z/1/

1127 posts
  • United Kingdom
  • Author Level 5
  • Affiliate Level 3
  • Collector Level 1
+5 more
Alexlasek
says

I’m sorry, I thought id put all the relevant coded needed. http://jsfiddle.net/rG92z/

Ignore the fact the button to open jumps down in the fiddle. The problem im having is getting the menu to close once a menu link has been clicked on

Tom
jQuery(document).ready(function($) { $(".ToggleMenu").click(function() { $("nav").slideToggle(500); }); $("nav a").click(function(){ $("nav").slideToggle(500); }); });

EDIT: sorry Gareth_Gillman, haven’t seen yours. cheers

47 posts
  • Author Level 1
  • Collector Level 3
  • United Kingdom
  • Exclusive Author
+1 more
Renny
says

Hi Renny hows this look? jsfiddle.net/rG92z/1/


I’m sorry, I thought id put all the relevant coded needed. http://jsfiddle.net/rG92z/

Ignore the fact the button to open jumps down in the fiddle. The problem im having is getting the menu to close once a menu link has been clicked on

Tom
jQuery(document).ready(function($) { $(".ToggleMenu").click(function() { $("nav").slideToggle(500); }); $("nav a").click(function(){ $("nav").slideToggle(500); }); }); EDIT: sorry Gareth_Gillman, haven’t seen yours. cheers

They both work perfectly! thank you very much for your help!

edit: is there a way to make a jquery run only in mobile/tablets?

1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
Gareth_Gillman
says

Have a read of this for mobiles and jQuery

by
by
by
by
by
by