Javascript CSSStyleDeclaration getPropertyPriority Method

Introduction

Return whether the color property has the "important!" priority set:

Click the button to return whether or not the color property has the "important!" priority set.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#ex1 {/*from w  ww.  ja  va  2s .  c  om*/
  color: red !important;
}
</style>
</head>
<body>
<button onclick="myFunction()">Test</button>

<div id="ex1">Some text.</div>

<p id="demo"></p>
<script>
function myFunction() {
  var declaration = document.styleSheets[0].cssRules[0].style;
  var priority = declaration.getPropertyPriority("color");
  document.getElementById("demo").innerHTML = priority;
}
</script>

</body>
</html>

The getPropertyPriority() method returns whether the CSS property has the "important!" priority set.

If this method returns "important", the important qualifier is set.

If this method returns an empty string, the important qualifier is not set.

getPropertyPriority(propertyname);

Parameter Values

ParameterDescription
propertyname Required. A String representing the name of the property to check



PreviousNext

Related