CSSStyleRule:selectorText 属性
CSSStyleRule 接口的 selectorText 属性用于获取和设置与 CSSStyleRule 相关联的选择器。
值
字符串。
示例
CSS 包含一条样式规则。这将是 document.styleSheets[0].cssRules 返回的第一个 CSSRule。因此,myRules[0].selectorText 返回选择器的字面量字符串,在本例中为 "h1"。
css
h1 {
color: pink;
}
js
let myRules = document.styleSheets[0].cssRules;
console.log(myRules[0].selectorText); // a string containing "h1".
规范
| 规范 |
|---|
| CSS 对象模型 (CSSOM) # dom-cssstylerule-selectortext |
浏览器兼容性
加载中…