English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
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‹/›
All browsers fully support the item() method:
Methode | |||||
item() | Ja | Ja | Ja | Ja | Ja |
Parameter | Beschreibung |
---|---|
index | Eine Zahl, die den Index der CSS-Eigenschaft darstellt. Der Index beginnt bei Null. |
Rückgabewert: | Eine Zeichenkette, die den Attributnamen darstellt |
---|---|
DOM-Version: | CSS-Objektmodell |
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‹/›