diff --git a/js/filter.js b/js/filter.js new file mode 100644 index 0000000..c7961b4 --- /dev/null +++ b/js/filter.js @@ -0,0 +1,18 @@ +const refs = { + buttonsFilter: document.querySelectorAll('.filters-list button'), + projects: document.querySelectorAll('.grid-portfolio__item'), +}; + +refs.buttonsFilter.forEach(button => { + button.addEventListener('click', () => { + const btnCategory = button.dataset.category; + + refs.projects.forEach(project => { + const projectCategory = project.dataset.category; + if (btnCategory === 'all' || btnCategory === projectCategory) { + return (project.style.display = 'block'); + } + return (project.style.display = 'none'); + }); + }); +}); diff --git a/portfolio.html b/portfolio.html index f27c703..b73ab1b 100644 --- a/portfolio.html +++ b/portfolio.html @@ -123,31 +123,21 @@

Portfolio