Change Style: a jQuery Plugin

A simple plugin allowing links to change the stylesheet of a page.

This plugin allows a user to manually change the stylesheets provided by an author who uses alternate stylesheets. This plugin simply takes a link (or a set of links) and looks for the matching alternate stylesheet, which is then set as active and the previous one disabled.

The plugin uses the query string of anchors, so if a user has JavaScript disabled you will still be able to process change of stylesheet in your serverside script.

You can manually set the query string key you want to use, which defaults to style.

You can also defined whether a cookie is stored when the user changes the stylesheet, although, this requires the jQuery cookie plugin. By default the plugin will create a cookie called change_stylesheet and stores the value of the query string.

If you use cookies, then you can set the correct stylesheet, in your serverside script, for that user when they next visit the site, or another page. The

If you enable the plugin on a anchor when it doesn’t match a stylesheet on the page, then the plugin will simply ignore it, and follow the anchor.

Download…

Want to use “Change Style” on your own website? No problem. You can download the full version.

Write Your Own…

Want to write your own plugin? I start all my plugins with a simple “skeleton” wrapper. Simply download my jQuery Plugin Skeleton and get started.

Run Code…

This page makes use of Run Code, a simple jquery plugin which converts your code examples to live behaviour.

Examples…

These links will store a cookie when a stylesheet is chosen.

$('.change a').changestyle();

I prefer the colour blue over red and the default is boring. These links will not store your choice in a cookie.

$('.change p a').changestyle({
  query : 'stylesheet',
  cookie : false
});