Close menu on click outside of menu area

More
9 years 1 month ago #29976 by cme
Thanks for the input. When firing the click event using
Code:
$('li.accordeonck.open').trigger('click');
I always ended up in an endless recursion, although I don't have a clue why...

But I think I found a pretty simple solution. At least it seams to work so far:
Code:
$( "body" ).click(function( event ) { if(!event.target.hasClass("toggler")){ $('li.accordeonck.open').removeClass('open'); $('ul.content_1').hide(); } });

I will test it a little more before going live.

cme

Please Log in or Create an account to join the conversation.

More
9 years 1 month ago - 9 years 1 month ago #30010 by cme
For some reason not working on iPads. Desktops and android tablets are fine.

I extended the if condition a little bit in order to keep the menu open until a new page is loaded if a link is clicked.
Code:
<script type="text/javascript">jQuery(function($){ $( "body" ).click(function( event ) { if(!event.target.hasClass("toggler")&&event.target.nodeName!="A"){ $('li.accordeonck.open').removeClass('open'); $('ul.content_1').hide(); } }); });</script>

cme
Last edit: 9 years 1 month ago by cme.

Please Log in or Create an account to join the conversation.

More
9 years 1 month ago #30011 by ced1870
thank you for sharing your solution. As you can see, it is not so easy to do that ;)

Joomlack Webmaster and Developer

Please Log in or Create an account to join the conversation.

Time to create page: 0.202 seconds

Fast and powerful creation, customizable and responsive.

Read More

We have 612 guests and one member online