2

I have made a toggle slide menu with jquery mobile And how to slides back up when click anywhere of div?

this is my jquery script here

<script>  
        $(document).ready(function () {
            $('.gnbLayer').hide();
            $(".icGnb5").click(function () {
                $(this).toggleClass("on");
                 $('.gnbLayer').slideToggle('medium');

            }); 
        }); 
        </script>
user3400080
  • 211
  • 1
  • 4
  • 16

2 Answers2

2

You can use:

$(document).click(function(){
 $('.gnbLayer').slideUp();
});

also modify click event to stoppropogation:

$(".icGnb5").click(function (e) {
             $(this).toggleClass("on");
             $('.gnbLayer').slideToggle('medium');
             e.stopPropagation();

        }); 
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0

You can use this,

  $(document).click(function(){
      $(".icGnb5").toggleClass("off");
      $('.gnbLayer').slideUp();
  });
KarthikManoharan
  • 805
  • 5
  • 12