1.0.0 • Published 5 years ago

easy-css-variables v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

easy-css-variables

CDN:

<script src="https://cdn.jsdelivr.net/gh/olian04/easy-css-variables/src/index.js"></script>

Demo:

https://jsfiddle.net/olian04/rxLfmgeq/41/

Global

const ecv = require('easy-css-variables');

ecv.backgroundColor = 'blue';
.greet {
  background: var(--backgroundColor);
}
<div class="greet">Hello!</div>

Target element

const ecv = require('easy-css-variables');

const seGreet = document.querySelector('.greet.se');

ecv('.greeter.en').backgroundColor = 'blue';
ecv(seGreet).backgroundColor = 'pink';

Note: The selector passed to ecv(selectorOrElement) needs to only match a single element, or the first one will be selected.

.greet {
  background: var(--backgroundColor);
}
<div class="greet en">Hello!</div>
<div class="greet se">Hej!</div>
1.0.0

5 years ago