Wednesday, October 11, 2023

dynamic CSS with JavaScript

 Dynamic style - manipulating CSS with JavaScript - W3C Wiki

how to dynamically update the styling applied to your elements by manipulating your CSS at runtime using JavaScript.

How to dynamically create CSS class in JavaScript and apply? - Stack Overflow

var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '.cssClass { color: #f00; }';

document.getElementById('someElementId').className = 'cssClass';
<div id="someElementId">test text</div>
javascript - changing CSS class definition - Stack Overflow

No comments: