mardi 24 février 2015

Using If/Else statement in jQuery

I am using a nav filter to highlight certain projects which are represented in a couple of lists. Each nav button, when clicked, will add the respective border around the projects that fall under that category. I have a very simplified version of the code here in jsFiddle.


JsFiddle



//what do i do here? if/else
$('li#all-btn').click(function() {
$("#projects").find("li.wrap").toggleClass("highlight-all");
});


The jsFiddle is not highlighting all of them like my original code does (adds black border), but I am wanting to change that to where it will highlight every project with their respective border color. I like the ability to toggle the border on and off as well.


I am thinking that the best way to achieve this would be an if/else statement within the jQuery, such as IF the project contains this class, THEN toggleClass("respective class"). How can I achieve this effect?


Aucun commentaire:

Enregistrer un commentaire