Home >Web Front-end >CSS Tutorial >How can I dynamically change CSS class rules in real time with jQuery?
Change CSS Class Rules Dynamically with jQuery
Your query involves two aspects:
1. Modifying Class Rules in Real Time
jQuery alone cannot alter CSS class rules dynamically. However, you can utilize the styleSheets property of the document object to access CSS rules directly.
Code:
<code class="javascript">document.getElementById("button").onclick = function() { var ss = document.styleSheets; for (var i = 0; i < ss.length; i++) { var rules = ss[i].cssRules; for (var j = 0; j < rules.length; j++) { if (rules[j].selectorText === ".classname") { rules[j].style.fontSize = "20px"; } } } };</code>
2. Saving Class Changes to File
To save class changes to a file, you need to extract the CSS rules and send them to the server via an Ajax request. The server-side implementation involves creating or updating a file with the modified rules.
Additional Notes:
References:
The above is the detailed content of How can I dynamically change CSS class rules in real time with jQuery?. For more information, please follow other related articles on the PHP Chinese website!