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

CSSStyleDeclaration item() method

 JavaScript CSSStyleDeclaration-Objekt

The CSSStyleDeclaration item() method is used to: return CSS property names 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;
Testen Sie heraus‹/›

Browser compatibility

All browsers fully support the item() method:

Methode
item()JaJaJaJaJa

Parameterwert

ParameterBeschreibung
indexEine Zahl, die den Index der CSS-Eigenschaft darstellt. Der Index beginnt bei Null.

Technische Details

Rückgabewert:Eine Zeichenkette, die den Attributnamen darstellt
DOM-Version:CSS-Objektmodell

Mehr Beispiele

Durchsuchen Sie alle Elemente nach Stylendeklarationen:

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;
}
Testen Sie heraus‹/›

 JavaScript CSSStyleDeclaration-Objekt