I am working with a list of divs that have zebra striping in CSS, where the odd divs have a light grey background. My goal is to change the background color of a clicked div to blue. However, I have encountered an issue where this only works for even divs, possibly due to the zebra striping having a higher specificity than the class added with addClass
. Rearranging the selectors in my CSS file has not resolved the problem.
div.row div:nth-child(odd) {
background-color: #fafafa;
}
.selectedRow {
background-color: #338FFF;
}
$('.js-div').on('click', function (e) {
$(e.toElement).addClass('selected_color');
}