Web Design with HTML and CSS

(National Geographic (Little) Kids) #1
Interactivity on the web

Lesson 10, Introduction to Interactivity 223

Hiding an element with jQuery.


In this exercise, you’ll create an expandable container the user can toggle open and closed.
The fi gures below show jQuery’s animation features. The fi rst image contains a box in its
initial view; readers interested in the calorie content of the smoothie can click the See calories
link to expand this section. The second image shows you the expanded box after the user has
clicked the button.


An example of the collapsible box you will create.


As you will see, jQuery lets you experiment with diff erent methods of expanding the box
and with the timing. The collapsible box will take two exercises to complete; in this fi rst
exercise, you will hide the section.


1 (Optional) Perform this step to see the code of the jQuery framework. Choose
File > Open. In the dialog box that appears, navigate to your web10lessons and open
the jquery.js fi le. Scroll to see the functions contained within the fi le. This fi le is well
commented, so you can get a sense of what the functions do. When you are fi nished,
close the fi le without saving it.


You can reference the functions in the jQuery document in your web page, but you rarely need to modify them.
Free download pdf