Wednesday, 7 August 2013

How would i go about shortening this code? And to cancel the previous click on click of new section?

How would i go about shortening this code? And to cancel the previous
click on click of new section?

My code below basically changes the image for people in a team sector, but
as you can see theres alot of repeated code; is there a way to shorten it?
Also it currently, allows you to click on all sections without turning off
the previously clicked one; i assume this is to do with the toggle()
function, but i couldn't get it to work any other way! still quite new to
jquery coding, so any help with that would be grand!!
Cheers in advance!
$("#team_client_services").click(function () {
if ($(".team_client_services").hasClass("team_hide")) {
$(".team_client_services").toggleClass("team_hide");
$(".team_client_services2").toggleClass("team_show");
} else {
$(".team_client_services").toggleClass("team_hide");
$(".team_client_services2").toggleClass("team_show");
};
});
$("#team_management").click(function () {
if ($(".team_management").hasClass("team_hide")) {
$(".team_management").toggleClass("team_hide");
$(".team_management2").toggleClass("team_show");
} else {
$(".team_management").toggleClass("team_hide");
$(".team_management2").toggleClass("team_show");
};
});
$("#team_products").click(function () {
if ($(".team_products").hasClass("team_hide")) {
$(".team_products").toggleClass("team_hide");
$(".team_products2").toggleClass("team_show");
} else {
$(".team_products").toggleClass("team_hide");
$(".team_products2").toggleClass("team_show");
};
});
$("#team_technical").click(function () {
if ($(".team_technical").hasClass("team_hide")) {
$(".team_technical").toggleClass("team_hide");
$(".team_technical2").toggleClass("team_show");
} else {
$(".team_technical").toggleClass("team_hide");
$(".team_technical2").toggleClass("team_show");
};
});
$("#team_accounts").click(function () {
if ($(".team_accounts").hasClass("team_hide")) {
$(".team_accounts").toggleClass("team_hide");
$(".team_accounts2").toggleClass("team_show");
} else {
$(".team_accounts").toggleClass("team_hide");
$(".team_accounts2").toggleClass("team_show");
};
});
$("#team_admin").click(function () {
if ($(".team_admin").hasClass("team_hide")) {
$(".team_admin").toggleClass("team_hide");
$(".team_admin2").toggleClass("team_show");
} else {
$(".team_admin").toggleClass("team_hide");
$(".team_admin2").toggleClass("team_show");
};
});

No comments:

Post a Comment