Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
216,032 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
216,032 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.