W3cubDocs

/DOM

CSSStyleRule.selectorText

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

Browser CompatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support Yes Yes 61
61
? — 61
Read-only; setting of this property not supported.
9 Yes Yes
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes Yes 61
61
? — 61
Read-only; setting of this property not supported.
Yes Yes ?

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleRule/selectorText