Определите ваш <td>All Dates</td>
однозначно. Присвойте тот же класс или какой-либо другой идентификатор всей вашей дате <td>s
. Дайте им обработчик кликов, который скрывает все элементы .box, за исключением одного с той же датой. В вашем примере вы не согласны с тем, чтобы сделать дату в <td>
такой же, как имя класса даты в ваших div-элементах, которое вам понадобится для того, что я сделаю.
<table class="left-dates">
<tr><td id="alldates">All Dates</td></tr>
<tr><td id="date">01 dec 2009</td></tr>
<tr><td id="date">02 dec 2009</td></tr>
<tr><td id="date">03 dec 2009</td></tr>
<tr><td id="date">04 dec 2009</td></tr>
</table>
// unhide all box elements
$("#alldates").click(function(e){ $(".box").show(); });
// For each date <td> element
$("#date").each(function(){
// assign a click event
$(this).click(function(e){
// when the user clicks, get the
// <td>'s text contents
var myval = $(this).text();
// and grab each element with the
// 'box' css class
$(".box").each(function(){
// for each of these 'box' elements,
// if it has a class matching the date
// they selected, return
if($(this).has(myval))
{
return;
}
else
{
// otherwise, hide itself
$(this).hide();
}
});
});
});