0

I have a nav in a box with this html:

<nav class="menu" id="theMenu"> <div class="menu-wrap"> <h1 class="logo"><a href="index.html#home">LOGO</a></h1> <i class="icon-remove menu-close"></i> <a href="#headerwrap">HOME</a> <a href="#information">INFO</a> <a href="#portfolio">Portfolio</a> </div> <!-- Menu button --> <div id="menuToggle"><i class="icon-reorder"></i></div> </nav> 

And this jQuery:

;(function(){ // Menu settings $('#menuToggle, .menu-close').on('click', function(){ $('#menuToggle').toggleClass('active'); $('body').toggleClass('body-push-toleft'); $('#theMenu').toggleClass('menu-open'); }); })(jQuery) 

Can you please help me and write me what I have to add in the js to close my menu when I click in the menu button but ALSO when I clicked outside ?

1

2 Answers 2

2

You can bind click on the whole body, for instance:

$(window).on('click', function() { $('#theMenu').removeClass('menu-open'); }) 

that's it. If 'themenu' has class 'menu-open', on window-click this class will be removed.

edit

Otherwise you can consider the example in this DEMO.

Sign up to request clarification or add additional context in comments.

7 Comments

I try this but doesn't work..
what do you mean for "doesn't work"? have you included jquery? console give you any error?
take a look at edit.. is this what you need?
First of all thank you very very much for your help! Second yes this is the action which I need but if I will implement this code I still cannot work the menu. You add an extra div and I add it also but still nothing...can you check my demo please here to see : link the nav button is on the up left corner
Check again demo, I've updated the link. Add a class to a-item, say calling it "menu-item", and add a check in document.on('click');
|
0
$(document).ready(function(){ $('#menuToggle, .menu-close').click(function() { $('toggle dive id').slideToggle('slow'); }); }); 

2 Comments

I try this but doesn't work..
have you included the jquery file

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.