So far, we’ve seen how to set and query the CSS styles and classes of individual elements. It is also possible to script CSS stylesheets themselves. This is not commonly done, but it can occasionally be useful and this section sketches out the technique.
When scripting stylesheets, there are two kinds of objects you
may need to work with. The first kind are the Element objects that
<link> elements that contain
or reference your stylesheets. These are regular document elements and
if you give them
id attributes, you
can select them with
document.getElementById(). The second kind
of object is a CSSStyleSheet object that represents the stylesheet
property is a read-only array-like object containing CSSStyleSheet
objects that represent the stylesheets associated with the document.
If you set the
title attribute of
<link> element that defines or
references the stylesheet, that title will be available as the
title property of the corresponding
The subsections that follow explain what you can do with these style and link elements and stylesheet objects.
Enabling and Disabling Stylesheets
The simplest stylesheet scripting technique is also the most
portable and robust.
<link> elements, and CSSStyleSheet
objects all define a
implies, if the
true, then the stylesheet is disabled ...