I'm a bit confused as to why this isn't working; I assume that because I'm adding the class and its not being added back into the collection I'm not sure.
Here it is on a jsbin http://jsbin.com/ayije although code is below also.
Either way I can only get the action to happen on an element once;
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$('.optional').click(function () {
$(this).removeClass('optional').addClass('selected');
return false;
});
$('.selected').click(function () {
$(this).removeClass('selected').addClass('rejected');
return false;
});
$('.rejected').click(function () {
$(this).removeClass('rejected').addClass('optional');
return false;
});
});
</script>
</head>
<body>
<style>
a {padding:2px;color:white;}
.optional {background-color:blue;}
.selected {background-color:green;}
.rejected {background-color:red;}
</style>
<div id="tagContainer">
<a href="#" class="rejected">a</a>
<a href="#" class="optional"">b</a>
<a href="#" class="selected">c</a>
</div>
</body>
</html>