Get one style item in JavaScript

Description

The following code shows how to get one style item.

Example


<html>
<head>
<title>Style Example</title>
<script type="text/javascript">
  function useMethods() {<!--  ww  w  .  ja v  a 2s .  c o  m-->
    var oDiv = document.getElementById("myDiv");
    alert(oDiv.style.item(0));
  }
</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





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window