I am working on a navigation filter that highlights projects based on their respective categories when clicked. I want to make it so that when the #all-btn is clicked, all items are highlighted in their designated colors. Currently, they are set to highlight in black, but I would like to change this to:
- Graphic design - green
- Web design - red
- Flat design - blue
I believe using an if/then statement in jQuery could accomplish this, but I'm unsure of how to implement it. For example:
if (the item has class graphic) {
$("#projects").find("li.graphic").toggleClass("highlight-graphic");
}
else if (item has class web) {
$("#projects").find("li.web").toggleClass("highlight-web");
}
else {
$("#projects").find("li.flat").toggleClass("highlight-flat");
}
What would be the best approach to achieve this and will this code work effectively?