Latest web development tutorials

HTML DOM Style visibility property

Style Object Reference Style Objects

Definition and Usage

Whether visibility attribute of the element should be visible.

visibility attribute allows authors to display or hide an element. Similar to the display attribute. However, the difference is, if you set display: none, will hide the entire element, if you set visibility: hidden, content elements will not be visible, but the elements remain the original position and size.

grammar

Set visibility properties:

Object.style.visibility="visible|hidden|collapse|inherit"

Returns visibility attributes:

Object.style.visibility

描述
visible 默认。元素是可见的。
hidden 元素是不可见的,但仍然影响布局。
collapse 当在表格行或单元格中使用时,该元素是不可见的(与 "hidden" 相同)。
inherit visibility 属性的值从父元素继承。

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support visibility property.

Note: IE7 and earlier versions do not support the "inherit" value.IE8 only provides! DOCTYPE supported "inherit". IE9 support "inherit".


Examples

Examples

Hide content elements:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function demoDisplay(){
    document.getElementById("p1").style.display="none";
}
function demoVisibility(){
    document.getElementById("p2").style.visibility="hidden";
}
</script>
</head>
<body>

<p id="p1">这是一些文本。</p>
<p id="p2">这是一些文本。</p>
<input type="button" onclick="demoDisplay()" value="隐藏显示属性的文本">
<input type="button" onclick="demoVisibility()" value="具有可见性属性的隐藏文本">

</body>
</html>

try it"


Style Object Reference Style Objects