title: Javascript body overflow: hidden
body: <p>I have been experimenting to try to get this to work.</p>
  
  <p>I have 2 checkboxes acting as part of my mobile CSS navigation menu for either side. I have a javascript that prevents more than 1 checkbox to be open at a time. It works.</p>
  
  <p>Now I am trying to add an <code>overflow:hidden</code> to the body when either 1 of the checkboxes is checked, obviously if nothing is checked then to remove <code>overflow:hidden</code>, but I can't seem to get the first part to work.</p>
  
  <p>I am fairly new to Javascript so any help would be appreciated. Thanks!
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function selectOnlyThis(id){
    var myCheckbox = document.getElementsByName("nav-check");
    
    Array.prototype.forEach.call(myCheckbox,function(el){
      if (id != el)
      {
       el.checked = false;
      }
    });
  
    if (id.checked == false)
    {
     id.checked = false;
    } else
    {
      id.checked = true; 
    } 
    if (id.checked == true)
    {
   $('body').css("overflow", "hidden");
    }
  }
  
  // Click, scroll to the top of the document
  function topFunction() {
    document.body.scrollTop = 0;
    document.documentElement.scrollTop = 0;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="l-btn"&gt;
    &lt;input id="lger" type="checkbox" name="nav-check" onclick="selectOnlyThis(this)"/&gt;
    &lt;label for="lger" onclick="topFunction()"&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&lt;/label&gt;
  &lt;/div&gt;
  
  &lt;div class="r-btn"&gt;
    &lt;input id="rger" type="checkbox"  name="nav-check" onclick="selectOnlyThis(this)"/&gt;
    &lt;label for="rger" onclick="topFunction()"&gt;&lt;span&gt;&lt;/span&gt;&lt;br/&gt;&lt;div&gt;Location&lt;/div&gt;&lt;/label&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>