adding css using js code example
Example 1: add style javascript
element.setAttribute("style", "background-color: red;");
element.style.backgroundColor = "red";
Example 2: how to give css style in javascript
document.getElementById("myH1").style.color = "red";
Example 3: js add css style to element
var style = document.createElement('style');
style.innerHTML =
'.some-element {' +
'color: purple;' +
'background-color: #e5e5e5;' +
'height: 150px;' +
'}';
var ref = document.querySelector('script');
ref.parentNode.insertBefore(style, ref);