stylesheet-inject

1.2.2 • Public • Published

stylesheet-inject

npm

Dynamically load CSS snippets and stylesheets at browser runtime. Standalone utility (no dependencies)

Install

npm install -S stylesheet-inject or use the CDN version.

Examples

Load remote stylesheet

NPM

var loadCss = require('stylesheet-inject').load;
loadCss('//example.com/path/to/resource.css', function (error, $link) {
  // error callback with <link/> DOM element provided
});

CDN

<script src="//unpkg.com/stylesheet-inject/dist/stylesheet-inject.min.js"></script>
<script>
var loadCss = stylesheetInject.load;
loadCss('//example.com/path/to/resource.css', function (error, $link) {
  // error callback with <link/> DOM element provided
});
</script> 

Inject raw CSS

NPM

var injectCss = require('stylesheet-inject').inject;
injectCss(
  'p { color: red; }' +
  'a { color: blue; }'
);

CDN

<script src="//unpkg.com/stylesheet-inject/dist/stylesheet-inject.min.js"></script>
<script>
var loadCss = stylesheetInject.inject;
injectCss(
  'p { color: red; }' +
  'a { color: blue; }'
);
</script> 

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.2.2
    1
    • latest

Version History

Package Sidebar

Install

npm i stylesheet-inject

Weekly Downloads

6

Version

1.2.2

License

MIT

Last publish

Collaborators

  • jdcrensh