I have an input field, in which, user is supposed to enter the color of text, that he want's to be displayed later. I was wondering, if there is a way to change css variables with javascript setProperty function, and instead of a value, the argument would be another javascript variable? for example:
elem.style.setProperty('--my-css-variable', anotherJsVariable);
Yes, just like you have.
Doing this is most of the point of CSS custom properties.