HTMLStyleElement: sheet 屬性
HTMLStyleElement 介面的一個只讀的 sheet 屬性,包含與該元素關聯的樣式表。
除非其 type 屬性不是 text/css,否則 StyleSheet 始終與 HTMLStyleElement 相關聯。
值
一個 StyleSheet 物件,如果與該元素沒有關聯,則為 null。
示例
假設 <head> 包含以下內容
html
<style id="inline-style">
p {
color: blue;
}
</style>
關聯的 HTMLStyleElement 物件的 sheet 屬性將返回描述它的 StyleSheet 物件。
js
const style = document.getElementById("inline-style");
console.log(style.sheet.cssRules[0].cssText); // 'p { color: blue; }'
規範
| 規範 |
|---|
| CSS 物件模型 (CSSOM) # dom-linkstyle-sheet |
瀏覽器相容性
載入中…