document.getelementbyid add style code example
Example 1: add style javascript
element.setAttribute("style", "background-color: red;");
element.style.backgroundColor = "red";
Example 2: javascript modify css
var el = document.getElementById("elementID");
el.style.css-property = "cssattribute";
el.style.backgroundColor = "blue";
$("#elementID").css("css-property", "css-attribute");
$("#elementID").css("background-color", "blue");
$("#elementID").css({"css-property": "css-attribute", "css-property": "css-attribute"});
$("#elementID").css({
"css-property": "css-attribute",
"css-property": "css-attribute"});
Example 3: adding styling to element using javascript
var elem = document.querySelector('#some-element');
elem.style.color = 'purple';
elem.style.backgroundColor = '#e5e5e5';
elem.style.height = '150px';
Example 4: style through javascript
element.style.backgroundColor = "red";
Example 5: how to change an element in a different elements code css
#container:hover > #cube { background-color: yellow; }
#container:hover + #cube { background-color: yellow; }
#container:hover #cube { background-color: yellow; }
#container:hover ~ #cube { background-color: yellow; }