可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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"; }
回答1:
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"; }
回答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'.
回答3:
use jquery .hide()
jsfiddle demo
$('.ad').hide();
回答4:
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"; }