Another option is to utilize a CSS variable (which is currently supported in the most recent web browsers)
div.container > div.box{ background: var(--box-bg-color, #D7F9FF); }
You can then utilize JavaScript to modify the value for --box-bg-color
from anywhere within div.box
or higher up.
document.querySelector('div.container').style.setProperty('--box-bg-color', 'green')
If you are unable to edit their CSS, you will need to make adjustments directly to that element's style:
var element = document.querySelector('div.container > div.box');
if (element) {
element.style.backgroundColor = '#00FF00';
}
Keep in mind that you are altering the specificity values that decide which CSS rules to apply. Also, if you wish to revert to the original style, you must remove the style
attribute from that element.
var element = document.querySelector('div.container > div.box');
if (element) {
element.style.backgroundColor = '';
}