css style in js 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: how to give css style in javascript
document.getElementById("myH1").style.color = "red";
Example 4: css in js
JSS is an authoring tool for CSS which allows you to use JavaScript to describe styles in a declarative, conflict-free and reusable way. It can compile in the browser, server-side or at build time in Node.
JSS is framework agnostic. It consists of multiple packages: the core, plugins, framework integrations and others.
Example 5: how to change css using javascript
document.getElementById("myText").className = "anyNewClass"