mardi 24 février 2015

If/Else statement in Jquery

JSFiddle


I have a navigation filter that when clicked, each project will be highlighted depending on what category they are under. I would like that when clicking the #all-btn, all the items will be highlighted their respective color. Right now, they are set to highlight black, but I would like to change that. For example,


Graphic design will be green, Web design will be red, Flat design will be blue.


I would think that an if/then statement in the jQuery could achieve this but not sure how to frame it up. I.E.



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 a good way to set this up, and would this work?


Aucun commentaire:

Enregistrer un commentaire