I’m working on a filtering solution and as a part of it I need to manipulate some dom elements via javascript (I’m taking a long string with comma separated values and splitting it on each comma and making a new dom element for each so that I can use the individual pieces of text for filtering (I’m making sure to apply the correct data attribute for the filtering parameter).
The issue is that when I do this the filter’s aren’t updating to be aware of all the new elements so I’m wondering how I can programmatically restart the filter instance once I’ve finished my DOM manipulation.
Here’s the current code I have
const updateGeoFilters = function () {
// Selectors for primary items
const TAGS = '[cr-filter-tag]';
const tags = document.querySelectorAll(TAGS);
// Get each work item and create individual tags from the tag text
tags.forEach((item) => {
if (!item) return;
const className = item.getAttribute('cr-filter-tag');
const tagText = item.textContent;
const tagArray = tagText.split(',');
tagArray.forEach((tag) => {
item.insertAdjacentHTML(
'afterend',
`<div class=${className} fs-list-field="geography">${tag}</div>`
);
});
item.remove();
//progromatically resstart CMS filters
});
};