JavaScript and DHTML

DHTML becomes dynamic when you start using JavaScript to manipulate divs. For example, if you have a div named myFirstDiv (as in Figure 13-2), you could use this JavaScript to hide the div:

window.getElementById('myFirstDiv').style.visibility = "hidden";

This line gets the element whose id is myFirstDiv and then gets its CSS style object and changes the visibility value of that style object from visible to hidden.

Figure 13-9 shows how you can hide a div when the user clicks a link.

Hiding a div

Figure 13-9. Hiding a div

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.