I'd like to add a class to one of my divs with a dynamic value generated in ts.
Say I have the following code to add a class:
let item = document.querySelector('.my-div');
item.classList.add('max-width');
let myMaxWidthValue = '200'; // this value is going to be generated by some fn
Now I would like to somehow make the class look like this in the css:
.max-width .innerItems {
max-width: myMaxWidthValue
}
Is this possible? It would be way more efficient for me to do it this way.
As you can tell by my CSS I want to set the class to the parent that contains many children elements.
I could do getElementsByClassName
and loop through each one with element[0].style.maxWidth = myMaxWidthValue
but there could be a TON of these children elements and it does not seem right to do it this way.