you will need to each through the li items. Then do the compare and if you have a match you can set the var to true then break out of the each using return false so you dont keep iterating when you already know the result.
$('.popular-list li a').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+'</li>');
}
});
redsquare
2009-08-06 19:49:10