Table of Contents
Each of these exercises uses the file
/exercises/index.html
included in the sample code. This
file has the jQuery library included at the bottom of the page. For some
exercises, you’ll be able to work directly in Firebug; for others, you will
need to include other scripts after the jQuery script tag as directed in the
individual exercises.
In some cases, you will need to consult the jQuery documentation in order to complete an exercise, as we won’t have covered all of the relevant information in the lecture. This is by design; the jQuery library is large, and learning to find answers in the documentation is an important part of the process.
Here are a few suggestions for tackling these problems:
First, make sure you thoroughly understand the problem you're being asked to solve. Ask questions if the problem isn't clear.
Next, figure out which elements you'll need to access in order to solve the problem, and determine how you'll get those elements. Use Firebug to verify that you're getting the elements you're after.
Finally, figure out what you need to do with the elements to solve the problem. It can be helpful to write comments explaining what you're going to do before you try to write the code to do it.
Do not be afraid to make mistakes! Do not try to make your code
perfect on the first try! Making mistakes and experimenting with solutions
is part of learning the library, and you’ll be a better developer for it.
Examples of solutions for these exercises are located in the
/solutions
directory in the sample code.
Open the file /exercises/index.html
in your
browser. Use the file /exercises/js/sandbox.js
or
work in Firebug to accomplish the following:
Select all of the div elements that have a class of "module".
Come up with three selectors that you could use to get the third item in the #myList unordered list. Which is the best to use? Why?
Select the label for the search input using an attribute selector.
Figure out how many elements on the page are hidden (hint: .length).
Figure out how many image elements on the page have an alt attribute.
Select all of the odd table rows in the table body.