Skip to content

Instantly share code, notes, and snippets.

@NV
Created November 3, 2013 03:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NV/7286433 to your computer and use it in GitHub Desktop.
Save NV/7286433 to your computer and use it in GitHub Desktop.
Parse CSS in a browser
var style = document.createElement('style')
var iframe = document.createElement('iframe')
document.body.appendChild(iframe)
iframe.contentDocument.documentElement.appendChild(style)
iframe.style.display = 'none'
style.textContent = 'a {color: red}'
style.sheet // CSSStyleSheet
style.sheet.cssRules[0].cssText // 'a { color: red; }'
style.sheet.cssRules[0].selectorText // 'a'
style.sheet.cssRules[0].style[0] // 'color'
style.sheet.cssRules[0].style.color // 'red'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment