I have a div element and would like to append new style attributes to it.
I have tried to do it like this:
element.setAttribute('style', 'property: value');
And it works, but if that element already had styles applied, they will all get overwritten.
Lets say I have this situation:
HTML:
<div id=styled></div>
JavaScript:
var styled = document.getElementById('styled');
styled.setAttribute('style', 'display: block');
This works, but if I need to append another style lets say:
styled.setAttribute('style', 'color: red');
I would then lose style added in previous setAttribute() method!
How can one append styles to elements with JavaScript?
Thanks!