A related issue is how to communicate a CSS value from JavaScript to CSS in real time (including for animation). Approach: use a property value ("variable") associated with the body element. Inherit it everywhere desired.
JS:
document.body.style.setProperty('--width1', '30px');
CSS:
#divA {width: var(--width1);}