how to put different color in a title with jquery array

Asked

Viewed 78 times

0

I would like to put different colors in title with a jQuery array, More without getting random, in case are preset colors I’m starting now to program, and would like the help of vcs. from now on Obridago

And that’s what I want to do like the picture below

inserir a descrição da imagem aqui

  • Voce does not need jquery for this, only css solves your problem.

1 answer

0

As Hudsonph said the best would be to use css as a solution, but if you need to manipulate an array you already know with jquery, try the following:

var cores = ['red', 'yellow', 'gray', 'orange', 'blue', 'red', 'yellow']

AddColors(cores);

function AddColors(cores){
  jQuery.each( cores, function( i, val ) {
    $(".container").append("<div id='"+i+"'>Bla bla bla</div>");
    $( "#" + i ).css("color", val);
  });
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.