Interactive online courses HTML Academy
2026-03-09 10:53 Diff

Meow! Psychologists recommend limiting how much content that you consume, so today I will only read news about games. The website needs a filter.

You can’t argue with either psychologists or Muffin, which means that we will create a news filter. The web designer added a dropdown list, or a select as it’s called in HTML, which lists the news categories. When a user selects a category from the list, only news from this category should be displayed on the page. If the “All News” option is selected, then you need to display news stories from all categories.

In order to filter, we need to find all of the news stories on the page and to compare the category of each of them with the selected filter value. If they match or if the “All News” option is selected, then the news story should remain on the page. And if the news category and the filter value do not match, then the news story should be hidden.

This filtering method is suitable if the filter value and elements that need to be filtered can be found directly in the markup. Remember that there are no universal solutions. It all depends on the specific situation.

So, let’s get down to business!

All of the news on the main page has the class news-block. Find them and write the resulting collection to a variable. Make sure that you have found all of the news. Add a temporary highlight to all the elements in the collection, and check that this highlight appears on each news page.

The highlight class is responsible for the highlighting. Use the for ofloop to add it to every element in the collection. In the future, we will use this class to highlight news stories from different categories. This will help with code debugging.