I need to dynamically change the color properties of two classes, but my current code is sluggish since these classes are repeated over 100 times throughout the code.
Any tips on optimizing this for better performance?
if (mainColor) {
var elColors = document.querySelectorAll('.color')
elColors.forEach(el => el.style.color = mainColor)
var elBgColors = document.querySelectorAll('.bg-color')
elBgColors.forEach(el => el.style.backgroundColor = mainColor)
}
(the user input provides the mainColor)