Javascript: Set CSS Styles Dynamically with Variable

Javascript Code Function to Set CSS Styles via Javascript, Dynamically, Without Having to Know in Advance Which Style you want to Set. You can also Change MULIPLE Properties at the Same Time

Home Short:

How to set css style with Javascript dynamically using a variable for the dom style property. In other words, instead of having to explicitly elem.style.background = '#eee', elem.style(javascript variable) = '';

The most portable and reusable way to be able to set dom element style properties using any property you wish, using the simple Javascript function below.

Example of how to use, if you want to change the fontsize of a paragraph element:

Example of how to use, if you want to change multiple properties of an element at the same time:

S
H
A
R
E