English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSSStyleDeclaration item() method

 JavaScript CSSStyleDeclaration Object

The CSSStyleDeclaration item() method is used to: return the CSS property name from CSSStyleDeclaration.

If the index is out of range, an empty string is returned.

The index starts from 0.

Syntax:

object.item(index)
var style = document.getElementById('s1').style;
var propertyName = style.item(1);   // Returns the second style listed
document.getElementById("result").innerHTML = propertyName;
Test and see‹/›

Browser compatibility

All browsers fully support the item() method:

Method
item()IsIsIsIsIs

Parameter Value

ParameterDescription
indexA number representing the index of the CSS property. The index starts from zero.

Technical Details

Return Value:A string representing the attribute name
DOM Version:CSS Object Model

More Examples

Traverse all element style declarations:

function myFunc() {
   var style = document.getElementById('s1').style;
   for (i = 0; i < style.length; i++) {
   propertyName += style.item(i) + "<br>";
   }
   document.getElementById("result").innerHTML = propertyName;
}
Test and see‹/›

 JavaScript CSSStyleDeclaration Object