var iosSelect = true, androidSelect = true, windowsSelect = true, allSelect = true; $(function () { $("#ios").click(function () { if (iosSelect) { $("#ios").attr("src", "/Content/images/icon/icon_Remember2.png"); iosSelect = false; } else { $("#ios").attr("src", "/Content/images/icon/icon_Remember3.png"); iosSelect = true; } }); $("#android").click(function () { if (androidSelect) { $("#android").attr("src", "/Content/images/icon/icon_Remember2.png"); androidSelect = false; } else { $("#android").attr("src", "/Content/images/icon/icon_Remember3.png"); androidSelect = true; } }); $("#windows").click(function () { if (windowsSelect) { $("#windows").attr("src", "/Content/images/icon/icon_Remember2.png"); windowsSelect = false; } else { $("#windows").attr("src", "/Content/images/icon/icon_Remember3.png"); windowsSelect = true; } }); $("#all").click(function () { if (allSelect) { $("#all").attr("src", "/Content/images/icon/icon_Remember2.png"); $("#ios").attr("src", "/Content/images/icon/icon_Remember2.png"); $("#android").attr("src", "/Content/images/icon/icon_Remember2.png"); $("#windows").attr("src", "/Content/images/icon/icon_Remember2.png"); allSelect = false; iosSelect = false; androidSelect = false; windowsSelect = false; } else { $("#all").attr("src", "/Content/images/icon/icon_Remember3.png"); $("#ios").attr("src", "/Content/images/icon/icon_Remember3.png"); $("#android").attr("src", "/Content/images/icon/icon_Remember3.png"); $("#windows").attr("src", "/Content/images/icon/icon_Remember3.png"); allSelect = true; iosSelect = true; androidSelect = true; windowsSelect = true; } }); });
:
After switching:
So many repeated codes... Is there a better way?