All style attributes can be accessed using the style object of the element. JS
//calling the function in window.onload to make sure the HTML is loaded
window.onload = function() {
    var x = document.getElementById("demo");
    x.style.color = '#6600FF';
    x.style.width = '100px';
};
HTML
<div id="demo" style="width:400px">Some text inside this DIV</div>
Note: All CSS properties can be set and modified using JavaScript. We cannot use dashes (-) in the property names: these are replaced with
camelCase
versions, where the compound words begin with a capital letter. For example: the
background-color
property should be referred to as
backgroundColor
.
by Valeri Tandilashvili
4 years ago
JavaScript
DOM
3
Pro tip: use ```triple backticks around text``` to write in code fences