element.css in javascript code example
Example 1: html css javascript
For example:
<div id="me">Click me!</div>
<style>
div {
height: 128px;
width: 128px;
background: red;
}
</style>
<script>
document.getElementById("me".addEventListener("click", function(){
document.getElementById("me").style.background = 'blue';
});
</script>
Example 2: 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 3: how to change css using javascript
document.getElementById("myText").className = "anyNewClass"