Summary

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.

Browser Compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support Yes Yes Yes19 Yes Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes Yes Yes1 Yes Yes ?

1. Read-only; setting of this property not supported

Specification

Document Tags and Contributors

 Contributors to this page: fscholz, mfluehr, bathos, cuixiping, teoli, miket, Sheppy, ethertank, Brettz9, Dria, JesseW
 Last updated by: fscholz,