214
Change the Visibility of an Object ...........................
2 In the document’s body, type
<div id=”?”>, replacing
? with an ID.
3 Type some text.
4 Type </div>.
1 In your editor, open a
document that contains a
script block.
Change the Visibility of an Object
J
avaScript is known as an object-based language. Basically, this means that your script relies on
calling and modifying programmatic objects, the most common of which is document, an object
that represents the Web page itself. The document object in turn contains a common function or
method, getElementById(), which returns an element on your page with the given ID. Using
this element, you can change CSS styles via the style object, including the visibility property
to show and hide elements. Thus, the line document.getElementById(“content”).
style.visibility = “hidden” would hide an element on the page that contained an ID
attribute set to content.