[英]Hide 'div' tag in JavaScript
I have JavaScript code that hides a tag when it is clicked: 我有JavaScript代码,点击它时会隐藏标记:
document.getElementById("div").style.visibility="hidden";
Although when I do this, even though the div tag is hidden, there is still a space where the div tag is located. 虽然当我这样做时,即使div标签被隐藏,但仍然存在div标签所在的空间。 how do I collapse the whole div tag using JavaScript?
如何使用JavaScript折叠整个div标签?
采用:
document.getElementById("div").style.display = 'none';
You should use: 你应该使用:
document.getElementById("div").style.display = "none";
Just to mention that getElementById()
will be looking for a div
with the id of div
, I suggest you change this to something more obvious, an example would be: 只是提及
getElementById()
将寻找一个div
用的ID div
,我建议你换这个东西比较明显的,一个例子是:
<div id="container"><!--Content--></div>
Then your JavaScript could be: 然后你的JavaScript可能是:
document.getElementById("container").style.display = "none";
Check here to see what the difference is between display:none
and visibility:hidden
点击此处查看
display:none
和visibility:hidden
之间的区别
尝试这个 ..
document.getelementById("div_id").style.display = 'none';
document.getElementById("yourdivID").style.display = 'none';
Use 采用
document.getElementById("divID").style.display = "none";
OR 要么
document.getElementsByTagName("div").style.display = "none";
NOTE: document.getElementById()
only select the elements having id
attributes. 注意:
document.getElementById()
仅选择具有id
属性的元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.