CSSStyleDeclaration item() Method
The item() method is used to return the property name of CSS from a CSS declaration block through index.
Syntax:
style.item(index)
Parameters: It accepts a single parameter:
- index: It is a required parameter that contains a number which represents the index of the CSS property.
Return Value: It returns the name of the CSS property in the form of the string.
Example: To show the working of the item() method:
<html> <head> <style> body { text-align: center; } h1 { color: green; } </style> </head> <body> <h1> GeeksforGeeks </h1> <p id="p1" style="color:green; font-size:20"> item() Method </p> <button onclick="myFunction()"> Get CSS property </button> <p id="gfg"></p> <!-- Script to get the property --> <script> function myFunction() { var x = document.getElementById("p1").style; var propertyName = x.item(1); document.getElementById("gfg").innerHTML = "Property at index 1 is " + propertyName; } </script> </body> </html> |
chevron_right
filter_none
Output:
Before clicking on the button:

After clicking on the button:

Supported Browsers:
- Google Chrome
- Internet Explorer 9.0
- Firefox
- Safari
- Opera
Recommended Posts:
- CSSStyleDeclaration getPropertyPriority() Method
- CSSStyleDeclaration getPropertyValue() Method
- CSSStyleDeclaration setProperty() Method
- HTMLCollection item() Method
- HTML | DOM item() Method
- CSSStyleDeclaration parentRule Property
- How to replace an item from an array in JavaScript?
- JavaScript | Remove the last item from an array
- PHP program to add item at the beginning of associative array
- How to remove indentation from an unordered list item using CSS?
- How to find if two arrays contain any common item in Javascript?
- How to insert an item into array at specific index in JavaScript?
- How to make the cursor to hand when a user hovers over a list item using CSS?
- jQuery | die() Method
- jQuery | off() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



