Uncaught TypeError: Cannot read property 'visibility' of undefined
<pre><code>function CheckavailOnload()
{
  var elems = document.getElementsByClassName('box-collateral box-related');
  for(var i = 0; i &lt; elems.length; i++){
  if(elems.style.visibility == 'visible')
  {
     var av = document.getElementsByClassName('availability in-stock');
     for(var i = 0; i &lt; elems.length; i++) {
     av[i].style.visibility = 'visible';
    }
  }
  else
  {
     var av = document.getElementsByClassName('availability in-stock');
     for(var i = 0; i &lt; elems.length; i++) {
     av[i].style.visibility = 'hidden';
    }
  }
 }
}
CheckavailOnload();
</code></pre>

<p>here i am trying to check the visibility of div "box-collateral box-related" if it is visible i want to toggel the visibility of another paragraph with class name "availability in-stock"</p>
