I have a small icon called "favorite" and when I click on it I call a jquery event handler to change the icon and change the class name.
But when I click on it again it doesnt go to the event handler of the class that I have added to it, it goes back to its original event handler
This is the icon
<input style="float:right" type="image" name="unfavorite" id="unfavorite" class="unfavorite" src="images/unfavorite.png" />
and my jquery is:
    $('.unfavorite').click(function()
    {
        $(this).removeClass('unfavorite');
        $(this).addClass("favorite");
        $(this).attr("src","images/favorite.png");
    });
    $('.favorite').click(function()
    {
        $(this).removeClass('favorite');
        $(this).addClass("unfavorite");
        $(this).attr("src","images/unfavorite.png");
    });
so basically I want to change the icon each time is clicked. But when I addClass(favorite) the event handler for favorite class is never called, it always goes to unfavorite
What should I do?
thank you
 
     
    