Get style value by property value in JavaScript

Description

The following code shows how to get style value by property value.

Example


<html>
<head>
<title>Style Example</title>
<script type="text/javascript">
function useMethods() {<!--   w w w.  j  a  v a2  s.  com-->
var oDiv = document.getElementById("myDiv");
alert(oDiv.style.getPropertyValue("background-color"));
}
</script>
</head>
<body>
<div id="myDiv" style="background-color: red; height: 50px; width: 50px"></div><br />
<input type="button" value="Use Methods" onclick="useMethods()" />
</body>
</html>

Click to view the demo

The code above generates the following result.

Get style value by property value in JavaScript