Javascript CSSStyleDeclaration item Method

Introduction

Return the first CSS property name from the style declaration of an element:

Click the button to return the first CSS property name from the style declaration of the element:

View in separate window

<!DOCTYPE html>
<html>
<body>
<h1>The item() Method</h1>
<div id="ex1" style="color:blue; font-family:monospace;">Some text</div>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>
<script>
function myFunction() {/* w ww .  ja va2s .c  om*/
  var style = document.getElementById('ex1').style;
  var propname = style.item(0);
  document.getElementById("demo").innerHTML = propname;
}
</script>

</body>
</html>

The item() method returns a CSS property name from a CSS declaration block by index.

The index starts at 0.

item(index);

Parameter Values

Parameter Description
index Required. A number representing the index of the CSS property

The item() method returns a String representing the name of the property.




PreviousNext

Related