Javascript CSSStyleDeclaration getPropertyValue Method

Introduction

Return the value of the color property:

Click the button to return the value of the color property.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#ex1 {/*  w ww  .j  av  a  2 s . c  o  m*/
  color: red;
}
</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 propvalue = declaration.getPropertyValue("color");
  document.getElementById("demo").innerHTML = propvalue;
}
</script>

</body>
</html>

The getPropertyValue() method returns the value of the specified CSS property.

getPropertyValue(propertyname);

Parameter Values

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

The getPropertyValue() method returns a String representing the value of the property.




PreviousNext

Related