Why is it that I can define a rule in CSS like this
.red {
background-color: red;
background-image: linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,0.01) 1%,rgba(0,0,0,1) 100%);
}
and everything works perfectly fine, but when I do this in JS
var red = document.getElementById('red');
red.style.backgroundColor = 'red';
red.style.backgroundImage = 'linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,0.01) 1%,rgba(0,0,0,1) 100%);';
It only seems to work in IE, and not Chrome or Firefox?
How do you get the same behavior when the styles need to be set in JavaScript?
var red = document.getElementById('red');
red.style.backgroundColor = 'red';
red.style.backgroundImage = 'linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,0.01) 1%,rgba(0,0,0,1) 100%);';
div {
display: inline-block;
color: white;
text-align: center;
text-shadow: 0 1px 5px black;
font-size: 2em;
vertical-align: top;
width: 200px;
height: 100px;
}
.red {
background-color: red;
background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.01) 1%, rgba(0, 0, 0, 1) 100%);
}
<div class="red">
CSS Styling
</div>
<div id="red">
Programmatic Styling
</div>
I'm currently running with the following versions:
- Firefox 45.0.1
- Chrome 49.0.2623.110
- IE 11.0.9600.18230