Datasheet
11
Chapter 1: Taking the Web to the Next Level
work, but the fact that the page is now interactive is a huge change. With
JavaScript, you can build applications, not just pages.
✓ The Count button dynamically changes the page. When you click the
Count button, new content is added to the page automatically. A pro-
gram counts how many times the Count button is pressed and adds text
to the “watch this space” section. As the user interacts with the page,
the page has material that wasn’t originally on the server.
Of course, this example is simple, but you will be able to add any kind of
text to any Web element dynamically. That’s a very powerful capability.
Figure 1-2 shows how the page looks after I click the Count button a few
times.
✓ The Toggle Visibility button makes things appear and disappear. You
can’t really modify whether things appear or go away in HTML. You can
do so in CSS to some level, but JavaScript gives you a much more power-
ful set of tools for changing what parts of the page are visible to the user
at any time. Look at Figure 1-3 to see the page with the output segment
hidden.
Figure 1-2:
The Count
button
changes the
text in part
of the page.
The Count button
A new line is added to this section each
time the user clicks the Count button.
05_417997-ch01.indd 1105_417997-ch01.indd 11 10/26/09 9:55 PM10/26/09 9:55 PM