8

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"; }

Friedpanseller
  • 654
  • 3
  • 16
  • 31

4 Answers4

13

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";
    }
Chris M
  • 4,036
  • 4
  • 20
  • 26
2

use jquery .hide()

jsfiddle demo

$('.ad').hide();
Sobin Augustine
  • 3,639
  • 2
  • 25
  • 43
2
$('.divClassName').hide();

This will solve your problem.

In your case it will be like below. $('.ad').hide(); This will hide all the elements with class name 'ad'.

Code Geek
  • 143
  • 1
  • 6
0

To make the content visible which is inside iframe - pls try below:

var frame = document.getElementById("chatFeed"); 
var msg2 =frame.contentDocument.getElementsByClassName("publisherWrapper");
for (i = 0; i < msg2.length; i++) {
msg2[i].style.visibility="visible";
}
Shilpa
  • 1