To dynamically apply darker shades of background using JavaScript, I have devised the following code.
.event-list .bg{
background:#eee;
padding:5px;
}
.grid .event-list:first-child .bg{
background: #2aac97
}
.grid .event-list:nth-child(2) .bg{
background: #29a4ac
}
.grid .event-list:nth-child(3) .bg{
background: #2a92ac
}
.grid .event-list:nth-child(4) .bg{
background: #2a7dac
}
.grid .event-list:nth-child(5) .bg{
background: #2967ac
}
.grid .event-list:nth-child(6) .bg{
background: #2a55ac
}
<div class="grid">
<div class="event-list row">
<div class="bg">Lorem Ipsum</div>
</div>
<div class="event-list row">
<div class="bg">Lorem Ipsum</div>
</div>
<div class="event-list row">
<div class="bg">Lorem Ipsum</div>
</div>
<div class="event-list row">
<div class="bg">Lorem Ipsum</div>
</div>
<div class="event-list row">
<div class="bg">Lorem Ipsum</div>
</div>
</div>
Although I achieved this using CSS, I now wish to implement it with JavaScript for dynamic content from the backend. What approach should I take?