theonlychase
7/17/2017 - 6:09 PM

Automatically Check Radio Button. Get Element(s) by classname. Convert that nodelist into an array. Add style to each element in the array.

Automatically Check Radio Button. Get Element(s) by classname. Convert that nodelist into an array. Add style to each element in the array.

<script>
  // Get the ID of the input and automatically check it
  document.getElementById("shipping1").checked = true;
  
  // Since the element itself only has a class, I get the element by classname. The variable give us a nodelist, which I convert into an array.
  var hello = document.getElementsByClassName('shipMethodTable');
  [].forEach.call(hello, function (el) {
    el.style.display = 'none';
  });
</script>