Get Property Priority in Javascript
Description
The following code shows how to get Property Priority in Javascript.
Example
<!DOCTYPE HTML>
<html>
<head>
<style title="core styles">
p {<!--from w ww . j a v a 2s. c o m-->
color: white;
background-color: gray !important;
padding: 5px !important;
}
</style>
</head>
<body>
<p id="block1">This is a test.</p>
<div id="placeholder"></div>
<script>
var placeholder = document.getElementById("placeholder");
displayStyles();
function displayStyles() {
var newElem = document.createElement("pre");
newElem.setAttribute("border", "1");
var style = document.styleSheets[0].cssRules[0].style;
for (var i = 0; i < style.length; i++) {
newElem.innerHTML += style[i] + " " + style.getPropertyPriority(style[i]) + " ";
}
placeholder.appendChild(newElem);
}
</script>
</body>
</html>