My page contains about 30 same-sized divs with different classes, such as:
.mosaic-block, .events, .exhibitions, .gallery, .sponsors, .hospitality, .workshops, .lectures {
background:rgba(0, 0, 0, .30);
float:left;
position:relative;
overflow:hidden;
width:6.36896%;
height:22.2287%;
margin:2px;
}
There is also a navi class:
<div id="navi">
<a href="#"><div id="t0" class="n0 lfloat"><img src="images/home.png"><span>Home</span></div></a>
<a href="#"><div id="t1" class="n1 lfloat"><img src="images/events.png"><span>Events</span></div></a>
<a href="#"><div id="t2" class="n2 lfloat"><img src="images/workshops.png"><span>Workshops</span></div></a>
<a href="#"><div id="t3" class="n3 lfloat"><img src="images/lectures.png"><span>Lectures</span></div></a>
<a href="#"><div id="t4" class="n4 lfloat"><img src="images/exhibitions.png"><span>Exhibitions</span></div></a>
<a href="#"><div id="t5" class="n5 lfloat"><img src="images/hospitality.png"><span>Hospitality</span></div></a>
<a href="#"><div id="t6" class="n6 lfloat"><img src="images/gallery.png"><span>Gallery</span></div></a>
<a href="#"><div id="t7" class="n7 lfloat"><img src="images/sponsors.png"><span>Sponsors</span></div></a>
</div>
When a user clicks on "Events" [div #t1], all boxes except those with the class .events should fade out. This functionality is implemented using JQuery. However, the code seems too lengthy. Is there a way to shorten it?
<script type="text/javascript">
$(function () {
$('a #t0').click(function() {
$("*").animate({
opacity: 1.0
}, 500 );
});
$('a #t1').click(function() {
$("#t1").toggleClass("active");
$(".exhibitions, .workshops, .sponsors, .hospitality, .lectures, .gallery").animate({
opacity: 0.0
}, 500 );
$(".events").animate({
opacity: 1.0
}, 500 );
});
</script>
The code for #t2, #t3, #t4 can be similar. How can I make this more concise?
EDIT#1
Do I need to write .click(function() 7 times for each #t individually and exclude that class when writing $(".exhibitions, .workshops, .sponsors, .hospitality, .lectures, .gallery").animate()? Also, how can I remove the active class when the user selects another option?