--- 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')}} 来表示该属性的优先级。

Syntax

var priority = style.getPropertyPriority(property);

参数

返回值

例子

下面的代码检查了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}}