Binding does not seem to take...
jQuery Newbie....I have a fairly simple piece of code that attached an onclick to an image. When you click the image it runs some ajax and then changes the image. It is then supposed to bind a new function the image onclick so that when you click the image again a different ajax call is made. It is possible I over complicated this, but have tried everything and it continues to make the call to the same function.
-
function addListing() {
var theid = replace(this.id,"fav_","");
$.post("/ajax/ajax_addToFavorites.cfm", { prospectId: theid },
function() {
changeFavIcon('fav_'+theid);
$(this).removeClass("addToList");
$(this).addClass("removeFromList");
$(this).unbind("click", addListing);
$(this).bind("click", removeListing);
} , "");
}
function removeListing() {
var theid = replace(this.id,"fav_","");
if(confirm("Are you sure you want to delete from your favorites?")) {
$.post("/ajax/ajax_removeFromFavorites.cfm", { prospectId: theid },
function() {
changeFavIcon2('fav_'+theid);
$(this).removeClass("removeFromList");
$(this).addClass("addToList");
$(this).unbind("click", removeListing);
$(this).bind("click", addListing);
} , "");
}
}
$('.addToList').click(addListing);
$('.removeFromList').click(removeListing);