Не проверял, но что-то типа:
document.addEventListener("DOMContentLoaded", function() {
const filters = document.querySelectorAll("[data-filter]");
Array.from(filters).forEach(filter => {
filter.addEventListener("click", function(event) {
event.preventDefault();
const categoryName = filter.dataset["filter"];
const categories = document.querySelectorAll("[data-cat]");
if (categoryName === "all") {
Array.from(categories).forEach(category =>
category.classList.remove("hide")
);
} else {
Array.from(categories).forEach(category => {
const workCat = category.dataset["cat"];
if (workCat !== categoryName) {
category.classList.add("hide");
} else {
category.classList.remove("hide");
}
});
}
});
});
});