stylesheet-inject
v1.2.2
Published
Dynamically load CSS snippets and stylesheets at browser runtime
Downloads
11
Maintainers
Readme
stylesheet-inject
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>