FiltersLesson 153Free preview
Filter Elements
This lesson is part of How To · All levels
Summary
This lesson expands the concept of filters from a simple list to a set of elements like a card or a block of content. Each element is checked based on text or data attributes, and then its visibility is adjusted according to matching results. This approach is useful for product galleries, directories, and dashboards with lots of cards.
Key points
- Save the reference of the elements in the array so that it can be easily repeated over and over again
- Use the data-* attribute for categories that are not visible as text
- Use the classList.toggle or hidden property to set visibility
- Always provide an "all" option so that the user can set the filter
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.