CSS variables can be manipulated via JavaScript since they have access to the Document Object Model (DOM).
Below is an example illustrating how you can develop a script to showcase and modify the –blue variable introduced in the preceding pages. If you’re not yet familiar with JavaScript, don’t worry; you can explore more about JavaScript in our JavaScript Tutorial.
Example
<script> // Get the root element var r = document.querySelector(‘:root’); // Create a function for getting a variable value // Create a function for setting a variable value |
The numbers in the table indicate the initial browser version that provides comprehensive support for the var() function.