I have a button click event that grabs names associated with checkboxes that are checked and adds them to a <ul>
with checkboxes on the right side of the page. This works fine I then have another button that will remove and <li>
's with checked checkboxes
from the <ul>
. This works to. The problem comes when you go to add back an item that has been deleted from the right side. The item is not on the page, so it obviously removed from the DOM, but it's as if it's stored in browser memory still. How do I go about clearing it out of memory? Code is below.
$('.add-people').click(function () {
$('.add-names:checked').each(function () {
var name = $(this).parent().siblings('td.name-cell').html();
if ($('ul.group-list').find(':contains(' + name + ')').length) {
//Name is already in list
} else {
var newLi = '<li><input id="name" class="remove-names" type="checkbox" name="' + name + '"><span>' + name + '</span></li>'
$('ul.group-list').append(newLi);
}
});
});
$('.remove-people').click(function () {
$('.remove-names:checked').each(function () {
$(this).parent().remove();
});
});