I have two seperate divs with the class filterTag which are using the data-filter to target checkboxes inside. I am trying to get the checkbox values into the required list1 or list2 areas.
I need my arrays to run seperately with the data-filter element so we have two clear lists as to what data will be pushed into the desired list1 or list2 divs depending on the checkbox value.
I need to use the data-filter element due to the way the templates are loaded, I can't customise the content within the filterTag container.
Please help, I am super close but getting stuck.
$(document).on('change', '.filterTag .ais-refinement-list__checkbox', function() {
getValueUsingParentTag();
});
function getValueUsingParentTag() {
var chkArray = [];
$('.filterTag .ais-refinement-list__checkbox:checked').each(function() {
var target2 = $(this).parentsUntil('.filterTag').parent().data('filter');
chkArray.push($(this).val());
return this.value;
});
var selected;
selected = chkArray.join(', ');
if (selected.length > 0) {
console.log(selected);
}
}
Here is my jsfiddle