Given the HTML Element object, is it possible to add the same style property twice to it without resorting to string manipulation?
Consider the following examples:
<div style="width: 90%; width: calc(100% - 5em);"></div>
<h1 style="font-weight: bold; font-weight: 800;"></h1>
<p style="color: #cccccc; color: rgba(255, 255, 255, 0.8);"></p>
As far as I can tell, setting styles through a property .style(e.g. element.style.color = "blue") or .style.setProperty(e.g. element.style.setProperty("color", "blue")) overwrites existing style properties rather than adding them.
Having multiple definitions of the same property allows us to use the cascading nature of CSS, allowing us to use more modern CSS property values when available, with a graceful return to “good enough” values where more recent additions are not supported. However, the only way I can do something like this is by manually manipulating the string.
source
share