You need to use the .live event for anchors with class removal. Also the context of this will be an anchor inside the binding, so you need to use .parent () for fadeOut and remove li
$('.popular-list li a').live("click",function() {
var stuff = $(this).text();
var hasDuplicate = false;
$('#favoritesdrinks li').each( function(){
if ($(this).text() === stuff ){
hasDuplicate = true;
return false;
}
});
if (hasDuplicate ) {
alert("Already Added") }
else {
$('#favoritesdrinks').append('<li>'+stuff+' --- <a href="#" class="remove">Remove Item </a> </li>');
}
});
$("a.remove").live('click', function(ev) {
ev.preventDefault();
$(this).parent().fadeOut(500, function(ev) {
$(this).remove();
});
});
source
share