Return the first CSS property name from the style declaration of the "ex1" element:
var style = document.getElementById("ex1").style;
var propname = style.item(0);
alert(propname);
Try it Yourself »
The item() method returns a CSS property name from a CSS declaration block, by index.
The index starts at 0.
Method | |||||
---|---|---|---|---|---|
item() | Yes | 9.0 | Yes | Yes | Yes |
style.item(
index)
Parameter | Description |
---|---|
index | Required. A number representing the index of the CSS property |
DOM Version: | CSS Object Model |
---|---|
Return Value: | A String, representing the name of the property |
Loop through all the element's style declarations:
for (i = 0; i < elmnt.style.length; i++) {
txt += elmnt.style.item(i)
}
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!