Filtering a Selection (^) ❘ 53
If a selection results in nothing, jQuery will return an empty array, and you can then check the
length property to see if anything were selected.
if (!yesterday.length)
{
If there were no adjacent preceding element, you need to move to the previous row. To do that, you
start with the
parent element using jQuery’s parent() method, which will be a
the
that
be
method. Because we’re counting from zero, and there are 7 days in a week, that will make the last
dren(), and prev() methods just to provide more context and information in your programming.
var lastWeek = today.parent('tr').prev('tr');
if (lastWeek.length)
{
yesterday = lastWeek.children('td').eq(6);
}
}
It is still possible that there is no
of the month and thus could occur as the fi rst child of the fi rst
length ensures that a
that a
if (yesterday.length)
{
yesterday.addClass('calendarYesterday');
}
Now that you have fi gured out which, if any,
is fi guring out which
element by using jQuery’s next() method on the selection representing today, and this will reference
the adjacent following
var tomorrow = today.next('td');
As with yesterday, you are not certain that there is a
the
were made.
if (!tomorrow.length)
{
If there is no
element representing today, and you proceed to the next
at that
[http://www.it-ebooks.info](http://www.it-ebooks.info)