Make 'overflow' --> 'auto' on Second Click

Try this:
https://stackoverflow.com/questions/44572859/a-function-that-runs-on-the-second-click

<script>
var timesClicked = 0;

$("#menu_button").click(function() {
  timesClicked++;

  if (timesClicked % 2 == 0) {
    //run on each second click
     e.preventDefault();
     $('body').css('overflow', 'auto');
     console.log("second" + timesClicked);
  } else {
    //run on each first click
    e.preventDefault();
    $('body').css('overflow', 'hidden');
    console.log("first" + timesClicked);
  }
});
</script>

Anyway, no way to answer “in general” (Not related to your code/project). Sometimes the counter is wrong (If also there is “Close” button -or- close by esc key and so on). This code is very basic.

https://codepen.io/ezra_siton/pen/ROjQKx?editors=1111

2 Likes