English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
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‹/›
All browsers fully support the item() method:
Method | |||||
item() | Is | Is | Is | Is | Is |
Parameter | Description |
---|---|
index | A number representing the index of the CSS property. The index starts from zero. |
Return Value: | A string representing the attribute name |
---|---|
DOM Version: | CSS Object Model |
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‹/›