html
<ul class="logoUl">
<li class="orange"></li>
<li class="blue"></li>
<li class="green"></li>
<li class="pink"></li>
</ul>
SCRIPT
if (selectedCategory == 'currentAll') {
var strString = "orange,blue,green,pink";
var strArray = strString.split(',');
$.each(strArray, function (index, value) {
$("ul.logoUl > li").addClass(value)
});
}
there are 4 li’s in the ul.logoUL making an image liek this
Some times the logo gets a background color which will reset the colors to gray
currently my code does this doesnt reset the colors back
Question:
How can iterate through li‘s one at a time while adding one class at a time in hopes to gain the original colors scheme via classes?
DEMO
Without loop:
DEMO
Note
As you’re changing
classto eachlito give them similarbackgroundsometimes, so when you want to give them their original color scheme again, it would be better to remove previously assigned colorclassfirst and then assign originalclassagain like following:DEMO