CSSNamespaceRule:prefix 屬性

Baseline 已廣泛支援

此功能非常成熟,並且在許多裝置和瀏覽器版本中都能正常工作。它自 ⁨2018 年 3 月⁩ 起就已在瀏覽器中可用。

CSSNamespaceRule 介面的只讀 prefix 屬性返回一個字串,其中包含與此名稱空間關聯的字首名稱。如果沒有這樣的字首,則返回一個空字串。

一個包含與此名稱空間關聯的字首的字串。如果沒有字首,則為空字串。

示例

樣式表包含兩個名稱空間規則。第一個沒有字首,第二個的字首是 svg。將返回兩個 CSSNamespaceRule 物件。第一個 prefix 屬性的值將為空字串,第二個為 svg

css
@namespace url("http://www.w3.org/1999/xhtml");
@namespace svg url("http://www.w3.org/2000/svg");
js
let myRules = document.styleSheets[0].cssRules;
console.log(myRules[0].prefix); // an empty string ""
console.log(myRules[1].prefix); // "svg"

規範

規範
CSS 物件模型 (CSSOM)
# dom-cssnamespacerule-prefix

瀏覽器相容性