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 |
瀏覽器相容性
載入中…