visibility style property
Specifies or returns whether the element is visible.
This property is useful if you want to hide or show the contents of an element.
Similar to display property, but if you set the visibility property to 'hidden', only the contents of the element
will be invisible, the element stays in its original position and size.
The display property with value 'none' hides the entire element.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: visibility |
Possible values:
The type of this property is string.
One of the following values:
If used on cell elements, 'collapse' has the same meaning as 'hidden'. | |||||||
Element is hidden. | |||||||
Takes the value of this property from the computed style of the parent element. | |||||||
Element is visible. |
Default: visible.
Example HTML code 1:
This example illustrates the use of the visibility property:
|
||||
<head> <style> .visible { visibility: visible; } .hidden { visibility: hidden; } </style> </head> <body> <div class="hidden">A hidden element</div> <div class="visible">A visible element</div> There is an invisible element at the first line of the page </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the visibility property in JavaScript:
|
||||
<head> <script type="text/javascript"> function ChangeVisibility (selectTag) { // Returns the index of the selected option var whichSelected = selectTag.selectedIndex; // Returns the text of the selected option var visiValue = selectTag.options[whichSelected].text; var div = document.getElementById ("myDiv"); div.style.visibility = visiValue; } </script> </head> <body> <div id="myDiv">change visibility!</div> <br /> <select size="3" onchange="ChangeVisibility (this);"> <option selected="selected" />visible <option />hidden <option />inherit </select> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, applet, b, bdo, big, blink, blockquote, body, button, caption, center, cite, code, col, colgroup, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, label, legend, li, listing, marquee, menu, nobr, object, ol, optgroup, option, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
Related pages:
External links:
visibility (MSDN)
visibility (Mozilla Developer Center)
visibility (Safari Reference Library)
visibility (W3C)
visibility (Mozilla Developer Center)
visibility (Safari Reference Library)
visibility (W3C)
User Contributed Comments