Skip to content

Instantly share code, notes, and snippets.

@max8hine
Created March 22, 2018 08:14
Show Gist options
  • Save max8hine/8b15d401dd77e9141b5f04688d88ad49 to your computer and use it in GitHub Desktop.
Save max8hine/8b15d401dd77e9141b5f04688d88ad49 to your computer and use it in GitHub Desktop.
CSSOM - CSS Object Model In JS
// 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