Skip to content
Generate and edit a dynamic Cascading Style Sheet using JavaScript.
JavaScript HTML
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
dist
lib
test
.editorconfig
.eslintrc
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
LICENSE.md
README.md
bower.json
package.json

README.md

stylesheet.js Build Status

Generate and edit a dynamic Cascading Style Sheet using JavaScript.

Getting Started

Install the script via bower:

bower install stylesheet.js --save

Include it in the head of your page:

…
<head>
  …
  <script src="/bower_components/stylesheet.js/dist/stylesheet.min.js"></script>
  …
</head>
…

You are now ready to go!

Documentation

Generate a new Instance:

var stylesheet = new Stylesheet();

#addRule

You can add new rules to that created stylesheet. It takes 3 parameters:

  • required String selector The CSS selector.
  • required String rules The CSS rules.
  • optional Number index An index, where to insert the rule at in the new stylesheet.

#deleteRule

To delete a rule, pass in the selector of that rule.

  • required String selector The CSS selector.

#clear

This will clear the whole stylesheet, leaving it empty without any rules.

Examples

var stylesheet = new Stylesheet();

stylesheet.addRule('.ninja', 'visibility: hidden;'); // Add a new rule
stylesheet.addRule('.bear', 'color: white;'); // Add a second rule
stylesheet.addRule('.bear', 'color: brown;', 0); // Add as first rule

stylesheet.deleteRule('.ninja'); // Delete the .ninja rule

stylesheet.clear(); // Clear all rules

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

License

Copyright (c) 2014 Robert Katzki. Licensed under the MIT license.

Something went wrong with that request. Please try again.