Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide div by class id

If I have <div id="ad1" class="ad"> and <div id="ad2" class="ad"> how can I hide both by hiding all divs with class ad

I tried document.getElementsByClassName(ad).style.visibility="hidden"; but only this works
function hidestuff(boxid){ document.getElementById(boxid).style.visibility="hidden"; }

like image 847
Friedpanseller Avatar asked Oct 29 '13 05:10

Friedpanseller


1 Answers

As Matt Ball's clue left, you need to iterate through the results of your getElementsByClassName result.

Try something along the lines of:

    var divsToHide = document.getElementsByClassName("ad");

    for(var i = 0; i < divsToHide.length; i++)
    {
    divsToHide[i].style.visibility="hidden";
    }
like image 73
Chris M Avatar answered Sep 29 '22 19:09

Chris M