Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 982363 of CSSStyleSheet

  • Revision slug: Web/API/CSSStyleSheet
  • Revision title: CSSStyleSheet
  • Revision id: 982363
  • Created:
  • Creator: Sebastianz
  • Is current revision? No
  • Comment Fixed page formatting
Tags: 

Revision Content

{{APIRef("CSSOM")}}

An object implementing the CSSStyleSheet interface represents a single CSS style sheet.

A CSS style sheet consists of CSS rules, each of which can be manipulated through an object that corresponds to that rule and that implements the {{domxref("CSSStyleRule")}} interface, which in turn implements {{domxref("CSSRule")}}. The CSSStyleSheet itself lets you examine and modify its corresponding style sheet, including its list of rules.

In practice, every CSSStyleSheet also implements the more generic {{domxref("StyleSheet")}} interface. A list of CSSStyleSheet-implementing objects corresponding to the style sheets for a given document can be reached by the {{domxref("document.styleSheets")}} property, if the document is styled by an external CSS style sheet or an inline {{HTMLElement("style")}} element.

Properties

{{domxref("CSSStyleSheet.cssRules")}}
Returns a {{domxref("CSSRuleList")}} of the CSS rules in the style sheet.
{{domxref("CSSStyleSheet.ownerRule")}}
If this style sheet is imported into the document using an {{cssxref("@import")}} rule, the ownerRule property will return that {{domxref("CSSImportRule")}}, otherwise it returns null.

Methods

{{domxref("CSSStyleSheet.deleteRule")}}
Deletes a rule from the style sheet.
{{domxref("CSSStyleSheet.insertRule")}}
Inserts a new style rule into the current style sheet.

Notes

In some browsers, if a stylesheet is loaded from a different domain, calling cssRules result in SecurityError.

Specifications

Specification Status Comment
{{SpecName("DOM2 Style", "css.html#CSS-CSSStyleSheet", "CSS2Properties")}} {{Spec2("DOM2 Style")}} Initial definition

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

See also

  • {{domxref("StyleSheet")}}

Revision Source

<div>{{APIRef("CSSOM")}}</div>

<p>An object implementing the <code>CSSStyleSheet</code> interface represents a single <a href="/en-US/docs/Web/CSS">CSS</a> style sheet.</p>

<p>A CSS style sheet consists of CSS rules, each of which can be manipulated through an object that corresponds to that rule and that implements the {{domxref("CSSStyleRule")}} interface, which in turn implements {{domxref("CSSRule")}}. The <code>CSSStyleSheet</code> itself lets you examine and modify its corresponding style sheet, including its list of rules.</p>

<p>In practice, every <code>CSSStyleSheet</code> also implements the more generic {{domxref("StyleSheet")}} interface. A list of <code>CSSStyleSheet</code>-implementing objects corresponding to the style sheets for a given document can be reached by the {{domxref("document.styleSheets")}} property, if the document is styled by an external CSS style sheet or an inline {{HTMLElement("style")}} element.</p>

<h2 id="Properties">Properties</h2>

<dl>
 <dt id="cssRules">{{domxref("CSSStyleSheet.cssRules")}}</dt>
 <dd>Returns a {{domxref("CSSRuleList")}} of the CSS rules in the style sheet.</dd>
 <dt id="ownerRule">{{domxref("CSSStyleSheet.ownerRule")}}</dt>
 <dd>If this style sheet is imported into the document using an {{cssxref("@import")}} rule, the <code>ownerRule</code> property will return that {{domxref("CSSImportRule")}}, otherwise it returns <code>null</code>.</dd>
</dl>

<h2 id="Methods">Methods</h2>

<dl>
 <dt id="deleteRule">{{domxref("CSSStyleSheet.deleteRule")}}</dt>
 <dd>Deletes a rule from the style sheet.</dd>
 <dt id="insertRule">{{domxref("CSSStyleSheet.insertRule")}}</dt>
 <dd>Inserts a new style rule into the current style sheet.</dd>
</dl>

<h2 id="Notes">Notes</h2>

<p>In some browsers, if a stylesheet is loaded from a different domain, calling <code>cssRules </code>result in <code>SecurityError.</code></p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th>Specification</th>
   <th>Status</th>
   <th>Comment</th>
  </tr>
  <tr>
   <td>{{SpecName("DOM2 Style", "css.html#CSS-CSSStyleSheet", "CSS2Properties")}}</td>
   <td>{{Spec2("DOM2 Style")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE&nbsp;Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("StyleSheet")}}</li>
</ul>
Revert to this revision