1<html>
2<body>
3
4<p id="p2">Hello World!</p>
5
6<script>
7document.getElementById("p2").style.color = "blue";
8</script>
9
10<p>The paragraph above was changed by a script.</p>
11
12</body>
13</html>
1// Getting the element first
2var myElement = document.querySelector("#myElement");
3
4// examples for updating styles
5myElement.style.color = "blue";
6myElement.style.backgroundColor = "red";
1// background-color
2<element>.style.backgroundColor = '#000';
3// background
4<element>.style.background = '#000';
5// color
6<element>.style.color = '#fff';
7// box-sizing
8<element>.style.boxSizing = 'border-box';
9// font-family
10<element>.style.fontFamily = '\'Times New Roman\', Times, serif';
11// font-size
12<element>.style.fontSize = '16px';
13// margin
14<element>.style.margin = 0;
15// padding
16<element>.style.padding = '20px';
17// width
18<element>.style.width = '100%';
19// height
20<element>.style.height = '100%';
21// margin-left
22<element>.style.marginLeft = 0;
23// font-weight
24<element>.style.fontWeight = 400;
1element.style.backgroundColor = "red"; // set the background color of an element to red