I am stuck with this problem.. So general idea is that i have check-boxes, and clicking on them, their value with remove button is appended on some div. Problem is that i can't uncheck that specific check-box by clicking on that appended item.
Here are the function's that i use for appending and removing elements.
function appendChoices() {
len = userChoices.length;
// if len === 0 then no need to check
if(!len) return false;
for(i = 0; i < len; i++){
option = userChoices[i];
$categoryDiv = $('#' + option.category + '-container');
$categoryDiv.append('<span class="filterItemAppended" data-item="'+option.value+'">'
+ '<a href="#" onClick="removeRecord('+ i +')"><span class="glyphicon glyphicon-minus"></span></a>'
+ option.value
+'</span>');
// We need this if reset button is used
$('#checkbox-list').show();
}
}
function removeRecord(i) {
$categoryDiv = $('#' + option.category + '-container');
userChoices.splice(i, 1);
for (var i = 0; i < userChoices.length; i++) {
$categoryDiv.append('<span class="filterItemAppended" data-item="'+option.value+'">'
+ '<a href="#" onClick="removeRecord('+ i +')"><span class="glyphicon glyphicon-minus"></span></a>'
+ option.value
+'</span>');
};
$('input[type=checkbox]').val(option.value).prop('checked', false);
localStorage.setItem('userChoices', JSON.stringify(userChoices));
updateDom();
location.reload();
}
All help is appreciated, thx in advance.
Aucun commentaire:
Enregistrer un commentaire