CSSStyleRule.selectorText

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.

概述

CSSRule.selectorText 属性返回 CSS 规则的选择符文本,只读。动态设置 CSS 规则,请看 Using dynamic styling information.

语法

string = cssRule.selectorText

例子

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

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

说明

浏览器解析选择符的时候可能会剔除不必要的空白字符

标准