Today, I code some JavaScript, but it really does not look good. So how can I optimize it with good extend and look delicious
if($("#active-flg").val() == 'clubInfo') {
$("[name='local-li']:eq(0)").addClass("active");
$("[name='local-li']:eq(1)").removeClass("active");
$("[name='local-li']:eq(2)").removeClass("active");
$("#manage-club-info").addClass("active");
$("#manage-club-config").removeClass("active");
$("#manage-club-phone").removeClass("active");
} else if($("#active-flg").val() == 'clubSeo') {
$("[name='local-li']:eq(0)").removeClass("active");
$("[name='local-li']:eq(1)").addClass("active");
$("[name='local-li']:eq(2)").removeClass("active");
$("#manage-club-info").removeClass("active");
$("#manage-club-seo").addClass("active");
$("#manage-club-phone").removeClass("active");
} else if($("#active-flg").val() == 'clubPhone') {
$("[name='local-li']:eq(0)").removeClass("active");
$("[name='local-li']:eq(1)").removeClass("active");
$("[name='local-li']:eq(2)").addClass("active");
$("#manage-club-info").removeClass("active");
$("#manage-club-seo").removeClass("active");
$("#manage-club-phone").addClass("active");
}
4
Answers
Try this..
What about this
While this is not code review,
Your code is multiple kinds of redundant, which isn’t good. One of the most fundamental reasons computers exist is to eliminate redundancy.
What you want to be doing is finding ways to iterate over the things you have recursively and leaving the redundancy up to the computer or better yet just sidestepping redundancy and only dealing with the values that you need to. AKA instead of:
You want something like: