Another way is to set your props via the style
attribute
var styleText = '-webkit-linear-gradient(red, blue); ' +
'-o-linear-gradient(red, blue); ' +
'linear-gradient(red, blue);'
el.setAttribute('style', styleText);
If you think you risk overriding any other styles already set inline you will want to get the current styles and then add the new ones on top:
var el = document.getElementById('myEl'),
currentStyle = el.getAttribute('style'),
styleText = 'background: -webkit-linear-gradient(top, red 0%,blue 100%); ' +
'background: -o-linear-gradient(top, red 0%,blue 100%); ' +
'background: -ms-linear-gradient(top, red 0%,#blue 100%);' +
'background: linear-gradient(to bottom, red 0%, blue 100%);';
el.setAttribute('style', currentStyle + styleText);
Here's a bin with an example.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…