Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8154711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:26:55+00:00 2026-06-06T16:26:55+00:00

html <ul class=logoUl> <li class=orange></li> <li class=blue></li> <li class=green></li> <li class=pink></li> </ul> SCRIPT if

  • 0

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 thisenter image description here
Some times the logo gets a background color which will reset the colors to gray like so

currently my code does this doesnt reset the colors backenter image description here

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:26:57+00:00Added an answer on June 6, 2026 at 4:26 pm
    var strString = "orange,blue,green,pink",
        strArray = strString.split(',');
    
    $("ul.logoUl > li").each(function (index, value) {
        $(this).addClass(strArray[index]);
    });
    

    DEMO

    Without loop:

    var strString = "orange,blue,green,pink",
        strArray = strString.split(',');
    
    $("ul.logoUl > li").addClass(function (index) {
        return strArray[index];
    });
    

    DEMO

    Note

    As you’re changing class to each li to give them similar background sometimes, so when you want to give them their original color scheme again, it would be better to remove previously assigned color class first and then assign original class again like following:

    var strString = "orange,blue,green,pink",
        strArray = strString.split(',');
    
    $("ul.logoUl > li")
        .removeClass() // first remove previous class
        .addClass(function (index) { // then add new class
            return strArray[index];
        });
    

    DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an HTML class in PHP, so that we can keep all
I'm trying to compare two numbers, and add an HTML class to the large
Is there any html form class(text box) that does not allow null values. The
I want to use the Html Helper class to build, for example, an Html.ActionLink
I'm defining a DU for the various classes I use within HTML: type Class
As detailed here among other places, the only valid characters in a html/css class
I am using web client class to HTML data from a web page. Now
Is there anyway to retrieve a HTML element's class or ID in the controller
I have html elements with class ajaxem that are ment to be used in
I have this html: <div id=signbtn> <a id=login-link class=btnsignin title=Login>Sign in</a> </div> Upon successful

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.