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.


string = cssRule.selectorText 


// for cssrule: body { background-color: darkblue; }
var stylesheet = document.styleSheets[0];

alert(stylesheet.cssRules[0].selectorText); // body


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.


Specification Status Comment
CSS Object Model (CSSOM)
The definition of 'CSSStyleRule.selectorText' in that specification.
Working Draft  

Browser Compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
selectorTextChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 9Opera Full support YesSafari Full support 6WebView Android Full support 4.4Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 1.0


Full support  
Full support