Set css style for an element

Set a CSS style

Setting the style via the style property:

ele.style.backgroundColor = 'red';
ele.style['backgroundColor'] = 'red';
ele.style['background-color'] = 'red';

Multiple styles can be set at the same time by overwriting or updating the cssText property:

// Add new style
el.style.cssText += 'background-color: red; color: white';

// Ignore previous styles
el.style.cssText = 'background-color: red; color: white';

Remove a CSS style


// Does NOT work

Might be useful