The CSSRule.selectorText
property gets the textual representation of the selector for the rule set. This is readonly in some browsers; to set stylesheet rules dynamically cross-browser, see Using dynamic styling information.
Syntax
string = cssRule.selectorText
Example
// for cssrule: body { background-color: darkblue; }
var stylesheet = document.styleSheets[0];
alert(stylesheet.cssRules[0].selectorText); // body
Notes
The implementation may have stripped out insignificant whitespace while parsing the selector. If set to a selector string which cannot be parsed, a SyntaxError is thrown.
Specifications
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM)The definition of 'CSSStyleRule.selectorText' in that specification. | Working Draft |
Browser Compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
selectorText
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 1 |
IE
Full support 9 |
Opera
Full support Yes |
Safari
Full support 6 |
WebView Android
Full support 4.4 |
Chrome Android
Full support 18 |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.0 |
Legend
- Full support
- Full support
CSSStyleRule.selectorText by Mozilla Contributors is licensed under CC-BY-SA 2.5.