Created
March 22, 2018 08:14
-
-
Save max8hine/8b15d401dd77e9141b5f04688d88ad49 to your computer and use it in GitHub Desktop.
CSSOM - CSS Object Model In JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CSS Module | |
// https://medium.com/dailyjs/high-performance-dynamic-styles-db28c873940 | |
// Create a <style> element. You can use an existing one as well. | |
const style = document.createElement(‘style’) | |
document.head.appendChild(style) | |
// Insert a CSS Rule to the sheet at position 0. | |
style.sheet.insertRule(‘.my-button {color: red}’, 0) | |
console.log(style.sheet.cssRules) | |
// Change the value | |
style.sheet.rules[0].style.color = ‘green’ | |
console.log(style.sheet.cssRules) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment