Html 按类 id 隐藏 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19650368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hide div by class id
提问by Friedpanseller
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
如果我有
<div id="ad1" class="ad">
以及
<div id="ad2" class="ad">
如何通过隐藏所有带有类广告的 div 来隐藏两者
I tried
document.getElementsByClassName(ad).style.visibility="hidden";
but only this worksfunction hidestuff(boxid){
document.getElementById(boxid).style.visibility="hidden";
}
我试过了,
document.getElementsByClassName(ad).style.visibility="hidden";
但只有这个有效function hidestuff(boxid){
document.getElementById(boxid).style.visibility="hidden";
}
回答by Chris M
As Matt Ball's clue left, you need to iterate through the results of your getElementsByClassName result.
正如 Matt Ball 的线索所剩无几,您需要遍历 getElementsByClassName 结果的结果。
Try something along the lines of:
尝试一些类似的东西:
var divsToHide = document.getElementsByClassName("ad");
for(var i = 0; i < divsToHide.length; i++)
{
divsToHide[i].style.visibility="hidden";
}
回答by Sobin Augustine
回答by Code Geek
$('.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'.
在您的情况下,它将如下所示。$('.ad').hide(); 这将隐藏所有类名为“ad”的元素。
回答by Shilpa
To make the content visible which is inside iframe - pls try below:
要使 iframe 内的内容可见 - 请尝试以下操作:
var frame = document.getElementById("chatFeed");
var msg2 =frame.contentDocument.getElementsByClassName("publisherWrapper");
for (i = 0; i < msg2.length; i++) {
msg2[i].style.visibility="visible";
}