$(document).ready(function() { $('.cat-item').each(function() { var colorArray = ['blue', 'violet', 'yellow', 'red', 'green', 'grey']; var listGroup = document.getElementById('list-group1'); if ($(this).hasClass('active')) { listGroup.style.background = (colorArray[$(this).index()]); } }); });
Here is the solution, can someone come in handy