--- title: CSSStyleDeclaration.getPropertyPriority() slug: Web/API/CSSStyleDeclaration/getPropertyPriority tags: - API - CSSDOM - Method - Reference translation_of: Web/API/CSSStyleDeclaration/getPropertyPriority ---
{{ APIRef("CSSOM") }}
CSSStyleDeclaration.getPropertyPriority() 方法会根据传入的CSS属性,返回一个 {{domxref('DOMString')}} 来表示该属性的优先级。
var priority = style.getPropertyPriority(property);
property
是一个{{domxref('DOMString')}},表示要检查的属性名。priority
是一个{{domxref('DOMString')}},用以表示属性优先级。存在,就返回(例如:"important"
);不存在,则返回空字符串。下面的代码检查了margin
,在CSS规则中是否被设置为 important 优先级。
var declaration = document.styleSheets[0].cssRules[0].style; var isImportant = declaration.getPropertyPriority('margin') === 'important';
Specification | Status | Comment |
---|---|---|
{{SpecName('CSSOM', '#dom-cssstyledeclaration-getpropertypriority', 'CSSStyleDeclaration.getPropertyPriority()')}} | {{Spec2('CSSOM')}} | |
{{SpecName('DOM2 Style', 'css.html#CSS-CSSStyleDeclaration', 'CSSStyleDeclaration')}} | {{Spec2('DOM2 Style')}} |
{{CompatibilityTable}}
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |