Managing active stylesheets using jQuery

Managing active stylesheets using jQuery


Hello all,
I've been trying to write some code to let users change stylesheets at
will and have run into a bit of confusion as to how each browser
reacts. There seems to be no uniform selector to get a list of
stylesheets that are currently applied or not.
I'm using a test page with two stylesheets, examples:
<link type="text/css" rel="stylesheet" href="default.css"
title="default" />
<link type="text/css" rel="alternate stylesheet" href="theme.css"
title="theme" />
I've tried multiple selectors and had somewhat random results from
each:
Using Firefox 3.5.2, IE 8.0.6001.18702 and Chrome 2.0.172.43. Results
seem to be uniform across jQuery 1.3.2 and the latest nightly.
Selector: link[rel*=stylesheet]
Result: Works correctly in all browsers.
Selector: link[rel*=stylesheet]:enabled and link[rel*=stylesheet]
[disabled=false]
Result:
Firefox: Does not find any stylesheets.
Chrome: Does not find any stylesheets.
IE: Finds both stylesheets.
Selector: link[@rel*=stylesheet]:enabled and link[@rel*=stylesheet]
[disabled=false]
Result:
Firefox: Finds only the default stylesheet, but throws a warning
about @rel.
Chrome: Finds both stylesheets.
IE: Finds both stylesheets.
Selector: link[@rel*=stylesheet]:disabled and link[@rel*=stylesheet]
[disabled=true]
Result:
Firefox: Finds only the alternate stylesheet, but also throws a
warning about @rel.
Chrome: Does not find any stylesheets.
IE: Does not find any stylesheets.
I'm assuming Firefox is the only browser that actually reports to the
DOM the disabled attribute on stylesheets, but if so, I'm not sure why
in Firefox you're forced to use @rel to get that information,
especially when using using the selector 'link[@rel*=stylesheet]'
throws a jQuery exception.
That all being said, $('link[@rel*=style]:enabled').attr('disabled',
true); and $("link[@rel=*style][title='theme']").attr('disabled',
false); seem to work across all browsers to turn stylesheets off and
on, despite the warnings.
So am I going about this all wrong? Should I be using some other
method to figure out if stylesheets are applied? Or would this be
classified as a bug?
Thanks!