Level 58
One solution is to use local storage to save the filter values and then retrieve them when the page is loaded again. Here's an example implementation:
// Get the filter inputs
const filterInputs = document.querySelectorAll('.filter-input');
// Save the filter values to local storage
function saveFilters() {
const filters = {};
filterInputs.forEach(input => {
filters[input.name] = input.value;
});
localStorage.setItem('novaFilters', JSON.stringify(filters));
}
// Load the filter values from local storage
function loadFilters() {
const filters = JSON.parse(localStorage.getItem('novaFilters'));
if (filters) {
filterInputs.forEach(input => {
if (filters[input.name]) {
input.value = filters[input.name];
}
});
}
}
// Save the filters when they change
filterInputs.forEach(input => {
input.addEventListener('change', saveFilters);
});
// Load the filters when the page is loaded
loadFilters();
This code assumes that the filter inputs have a name attribute that matches the filter key in the local storage object. You may need to adjust the code to match your specific use case.