The goog.cssom Namespace

The goog.cssom.CssRuleType Enum

Enumeration of {@code CSSRule} types. … more

.addCssRule(cssStyleSheet, cssText, opt_index)

Cross browser function to add a CSSRule into a CSSStyleSheet, optionally at a given index.

cssStyleSheet {CSSStyleSheet}
The CSSRule's parentStyleSheet.
cssText {string}
The text for the new CSSRule.
opt_index {number=}
The index of the cssRule in its parentStylesheet.
@throws
{Error} If the css rule text appears to be ill-formatted. TODO(bowdidge): Inserting at index 0 fails on Firefox 2 and 3 with an exception warning "Node cannot be inserted at the specified point in the hierarchy."

.addCssText(cssText, opt_domHelper)

Appends a DOM node to HEAD containing the css text that's passed in.

cssText {string}
CSS to add to the end of the document.
opt_domHelper {goog.dom.DomHelper=}
Optional DOM helper user for document interactions.
returns {Element}
The newly created STYLE element.

.getAllCssStyleRules(opt_styleSheet)

Recursively gets all CSSStyleRules, optionally starting from a given CSSStyleSheet. Note that this excludes any CSSImportRules, CSSMediaRules, etc..

opt_styleSheet {CSSStyleSheet=}
The CSSStyleSheet.
returns {Array.<CSSStyleRule>}
A list of CSSStyleRules.

.getAllCssStyleSheets(opt_styleSheet, opt_includeDisabled)

Gets all CSSStyleSheet objects starting from some CSSStyleSheet. Note that we want to return the sheets in the order of the cascade, therefore if we encounter an import, we will splice that CSSStyleSheet object in front of the CSSStyleSheet that contains it in the returned array of CSSStyleSheets.

opt_styleSheet {CSSStyleSheet=}
A CSSStyleSheet.
opt_includeDisabled {boolean=}
If true, includes disabled stylesheets, defaults to false.
returns {Array.<CSSStyleSheet>}
A list of CSSStyleSheet objects.

.getAllCssText(opt_styleSheet)

Recursively gets all CSS as text, optionally starting from a given CSSStyleSheet.

opt_styleSheet {CSSStyleSheet=}
The CSSStyleSheet.
returns {string}
css text.

.getCssRuleIndexInParentStyleSheet(cssRule, opt_parentStyleSheet)

Get the index of the CSSRule in it's CSSStyleSheet.

cssRule {CSSRule}
A CSSRule.
opt_parentStyleSheet {CSSStyleSheet=}
A reference to the stylesheet object this cssRule belongs to.
returns {number}
The index of the CSSRule, or -1.
@throws
{Error} When we cannot get the parentStyleSheet.

.getCssRulesFromStyleSheet(styleSheet)

Returns the CSSRules from a styleSheet. Worth noting here is that IE and FF differ in terms of what they will return. Firefox will return styleSheet.cssRules, which includes ImportRules and anything which implements the CSSRules interface. IE returns simply a list of CSSRules.

styleSheet {CSSStyleSheet}
The CSSStyleSheet.
returns {CSSRuleList}
An array of CSSRules or null.
@throws
{Error} If we cannot access the rules on a stylesheet object - this can happen if a stylesheet object's rules are accessed before the rules have been downloaded and parsed and are "ready".

.getCssTextFromCssRule(cssRule)

Gets the cssText from a CSSRule object cross-browserly.

cssRule {CSSRule}
A CSSRule.
returns {string}
cssText The text for the rule, including the selector.

.getFileNameFromStyleSheet(styleSheet)

Cross browser method to get the filename from the StyleSheet's href. Explorer only returns the filename in the href, while other agents return the full path.

styleSheet {!StyleSheet}
Any valid StyleSheet object with an href.
returns {?string}
filename The filename, or null if not an external styleSheet.
@throws
{Error} When there's no href property found.

.getParentStyleSheet(cssRule)

We do some trickery in getAllCssStyleRules that hacks this in for IE. If the cssRule object isn't coming from a result of that function call, this method will return undefined in IE.

cssRule {CSSRule}
The CSSRule.
returns {CSSStyleSheet}
A styleSheet object.

The goog.cssom.iframe Namespace

… more

.removeCssRule(cssStyleSheet, index)

Cross browser function to remove a CSSRule in a CSSStyleSheet at an index.

cssStyleSheet {CSSStyleSheet}
The CSSRule's parentStyleSheet.
index {number}
The CSSRule's index in the parentStyleSheet.

.replaceCssRule(cssRule, cssText, opt_parentStyleSheet, opt_index)

Replace a cssRule with some cssText for a new rule. If the cssRule object is not one of objects returned by getAllCssStyleRules, then you'll need to provide both the styleSheet and possibly the index, since we can't infer them from the standard cssRule object in IE. We do some trickery in getAllCssStyleRules to hack this in.

cssRule {CSSRule}
A CSSRule.
cssText {string}
The text for the new CSSRule.
opt_parentStyleSheet {CSSStyleSheet=}
A reference to the stylesheet object this cssRule belongs to.
opt_index {number=}
The index of the cssRule in its parentStylesheet.
@throws
{Error} If we cannot find a parentStyleSheet.
@throws
{Error} If we cannot find a css rule index.