0

I'm creating a color wheel that has 360 colors. The gist of my markup looks like this:

HTML:

<table class="table1">
  <td class="medium-grey"></td>
  <td class="charcoal"></td>
  <td class="black"></td>
  ...

CSS:

.medium-grey { background-color: #76878e; }
.charcoal { background-color: #534259; }
.black { background-color: #060807; }

I am adding a background color via CSS to each td. I have alot of colors to manually add to each table and am finding this cumbersome. I am curious if there's a way I can loop through groups of colors to append to td classes with javascript or sass mixins.

1 Answer 1

1
var css_classes =['medium-grey' , 'charcoal', 'black'];

var idx = 0
$( "table.table1 td" ).each(function( index ) {
    $(this).addClass(css_classes[idx]);
    if (idx < css_classes.length-1){
      idx+=1;
    }else{
      idx = 0;
    }
});

given css classes, iterate td, and assign css classes in order.

refer to : jsfiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Baller. This is what I wanted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.