--- title: CSSStyleRule.selectorText slug: Web/API/CSSStyleRule/selectorText translation_of: Web/API/CSSStyleRule/selectorText ---
CSSRule.selectorText
属性返回CSS规则的选择符文本,只读。动态设置CSS规则,请看 Using dynamic styling information.
string = cssRule.selectorText
// for cssrule: body { background-color: darkblue; } var stylesheet = document.styleSheets[0]; alert(stylesheet.cssRules[0].selectorText); // body
浏览器解析选择符的时候可能会剔除不必要的空白字符