Skip to content

Instantly share code, notes, and snippets.

@ephys
Last active December 13, 2017 00:22
Show Gist options
  • Save ephys/0739af337e8007be7ab3c9f4174d8a65 to your computer and use it in GitHub Desktop.
Save ephys/0739af337e8007be7ab3c9f4174d8a65 to your computer and use it in GitHub Desktop.

Loading a styleSheet via HTMLLinkElement

The creation process of CSSStyleSheets is different in almost all browsers:

  • Chrome sets HTMLLinkElement.sheet once the sheet is loaded, it is null before that.
  • Firefox sets HTMLLinkElement.sheet immediately but accessing its properties throws an InvalidAccessError.
  • Edge sets HTMLLinkElement.sheet immediately, and accessign its properties return default values
    • CSSStyleSheet.cssRules is empty.
    • CSSStyleSheet.cssText is an empty string.

Proposed solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment