I'm trying to make a cycle so that if you click on a list item it goes green, if clicked again it goes red, once more and it goes into its original state, there are some items in the list that will already have either green or red classes. So far I've written this but it isn't working:
$(document).ready(function () {
$("li").click(function () {
if (this.hasClass ("red")) {
$(this).removeClass("red")
}
if (this.hasClass ("green")) {
$(this).addClass("red").removeClass("green")
}
else ($(this).addClass("green"))
}); });
Thank you for your help.