Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Maya Benari
Maya Benari
750 Points

Learn how to build a filter with JavaScript

Is there a course offered here that teaches you how to build a filter like you see on most shopping sites? For example, a page of items that I can filter by categories without reloading the page. Thanks! /cc Dave McFarland

4 Answers

Steven Parker
Steven Parker
231,122 Points

Yes, that kind of thing is in one or more courses here.

I remember doing it, but I don't have a specific course title in mind. But you can select courses in the library, and preview the contents of each stage. You can probably spot an individual video by the title that would have examples of this kind of task.

Maya Benari
Maya Benari
750 Points

Glad to hear it's offered, hopefully somebody will be able to tell me the name of the course. Searching for "filter" didn't find anything.

Maya Benari
Maya Benari
750 Points

I noticed the Treehouse library adds categories as classes to the elements its filtering:

<li class="card course syllabus topic-javascript personalized" data-location="library" data-featurette="library-card" data-activity="syllabus/3152" id="Syllabus-3152">...</li>

and i was just wondering, is that a best practice? Adding classes to cards to select them? Do people ever prefix them so there's no conflict in your CSS?

Steven Parker
Steven Parker
231,122 Points

Identification by class is indeed a "best practice".

It generally provides the best opportunities for future content expansion.

Do you mean prefix for the purpose of making each instance of the class unique? If so, yes that's a common practice but more often it is not necessary and it can be useful to have related elements share a class. The CSS would then intentionally target them together.