I Have this function, I would like to use the same function for 3 other sections on the same page.
I have tried putting "this" and closest but it doesn't work correctly. Any thoughts?
I have a UL with a class of "contain" I have also wrapped each section into it's own div of "subSet" so it becomes the "parent".
//Sign Up Favorites Function For Clicking
$('.popular-list li a').live("click",function() //this will apply to all anchor tags
{
var stuff = $(this).text();
var hasDuplicate = false;
$('ul.contain li').each( function(){
if ($(this).text() === stuff ){
hasDuplicate = true;
return false;
}
});
if (hasDuplicate ) {
$("#error").queue(function () {
$(this).fadeIn(500);
$(this).html('You Have Already Added '+stuff);
$(this).animate({opacity: 1.0}, 2000)
$(this).fadeOut(1500);
$(this).dequeue();
});
}
else {
$('ul.contain').append('<li title="Delete '+ stuff + '">'+stuff+'</li>');
}
});
//Sign Up Favorites Function For Adding Custom
$('a.addnew').live("click",function() //this will apply to all anchor tags
{
var newstuff = $("#create-new-drink").val();
var hasDuplicate = false;
$('ul.contain li').each( function(){
if ($(this).text() === newstuff ){
hasDuplicate = true;
return false;
}
});
if (hasDuplicate ) {
$("#error").queue(function () {
$(this).fadeIn(500);
$(this).html('You Have Already Added '+newstuff);
$(this).animate({opacity: 1.0}, 2000)
$(this).fadeOut(1500);
$(this).dequeue();
});
}
else if(newstuff === '') { $("#error").queue(function () {
$(this).fadeIn(500);
$(this).html('The Box is Empty');
$(this).animate({opacity: 1.0}, 2000)
$(this).fadeOut(1500);
$(this).dequeue();
});
}
else {
$('ul.contain').append('<li title="Delete '+ newstuff + '">'+newstuff+'</li>');
}
});
//Remove an Item
$("ul.contain li").live('click', function(ev) {
ev.preventDefault();
$(this).fadeOut(500, function(ev) {
$(this).remove();
});
});
This is the HTML to match:
<div class="subStep">
<h3>Section Headline</h3>
<ul class="contain">
<span id="error" class="notice"></span>
</ul>
<ul class="popular-list">
<h4>Headline</h4>
<li><a href="javascript:;">Dummy Text</a></li>
</ul>
<p class="create-entry">Add Your Own: <input type="text" name="createnew" value="" id="create-new" title="" /><a href="javascript:;" class="addnew button">Add New</a></p>
</div>