Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to condition a class

I’m new to JS and I want to know if there’s any possible way to condition a class

I’ll put you in context.
I’m trying to disable the scroll-bar for my mobile navbar and I got this so far:

<style>
  .no-scroll {
    overflow: hidden;
  }
</style>

<script>
  $('.checkbtn').on('click', function() {
    $('body').toggleClass('no-scroll');
  });
  if (I NEED YOUR HELP HERE) {
    $('.checkbtn').on('click', function() {
      $('body').removeClass('no-scroll');
    });
  }
</script>

Am I doing fine so far? Anyway, my question is how can I tell IF that ‘body’ has to have no-scroll class for it to work

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Edit: My hamburger navbar icon class is called ".checkbtn"

>Solution :

you can use hasClass method

for example

if($('body').hasClass('no-scroll'){
  // your code
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading