Web Development with jQuery®

(Elliott) #1

Filtering a Selection (^) ❘ 55
.addClass('calendarThisWeek');
};
The exercise of sibling discovery that you underwent with the method setUpThisWeek() can be
explored using a tool like Web Inspector in Safari or Chrome, Firebug in Firefox, and Developer
Tools in IE. Pictured in Figure 2-4 is Web Inspector in Safari, which shows the class names that you
assigned for each element representing a day or collection of days in the week surrounding the


element that represents today.

FIGURE 2-4


The next hunk of code defi nes some interactivity with the calendar:


➤ (^) Selecting a day in the calendar
➤ (^) Selecting the week that day occurs within
➤ (^) Setting the selected day in date format in the calendar heading
➤ (^) Changing the day that represents today
The fi rst thing you do is to create a new variable that will keep track of the selected day. This vari-
able is created outside the function that fi res when you click each day, so that it can persist and
remain present between click events. And that variable is called selectedDay.
var selectedDay = null;
You then make a selection that starts out with all the elements that are present in the


representing the month.
$('table.calendarMonth td')
http://www.it-ebooks.info