dimanche 31 mai 2020

Apply one of five colours randomly to series of links [duplicate]

I have a large number of links with the class folioLink i'm trying to use JS to pick one of five pre-determined colours and randomly apply across all the links. i.e. so each link with this class will have one of these colours randomly assigned.

So far I have:

  var colors = ['skyblue', 'mediumseagreen', 'orange', 'lightcoral', 'lightcoral','red'];
$('.folioLink').css('color', function(index) {
  return colors[index % colors.length];
});

Which is assigning the colours - but only in this sequence which then repeats. What can I add here to apply the colours at random? Thanks!




Aucun commentaire:

Enregistrer un commentaire