CSSStyleDeclaration getPropertyPriority() Method
Last Updated :
15 Jul, 2022
The getPropertyPriority() method is used to check whether the specified CSS property has the priority set as “important” or not.
Syntax:
object.getPropertyPriority(propertyname)
Parameters: It accepts a single parameter:
- propertyname: It is a required parameter that contains a string which represents the name of the property to be checked.
Return Value: It returns the priority of the property in the form of the string. If it does not exist then it returns an empty string.
Example: To show the working of the getPropertyPriority() method:
html
< html >
< head >
< style >
body {
text-align: center;
}
h1 {
color: green;
}
#p1 {
color: green;
font-size: 20 !important;
}
</ style >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< p id="p1">
getPropertyPriority() Method
</ p >
< button onclick="myFunction()">
Get property priority
</ button >
< p id="gfg"></ p >
< script >
function myFunction() {
var x =
document.styleSheets[
0].cssRules[2].style;
var prior =
x.getPropertyPriority(
"font-size");
document.getElementById("gfg").innerHTML =
"Priority of font-size is " + prior;
}
</ script >
</ body >
</ html >
|
Output:
Before clicking on the button:
After clicking on the button:
Supported Browsers:
- Google Chrome 1
- Edge 12
- Internet Explorer 9
- Firefox 1
- Safari 1
- Opera 12.1
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...