CSSStyleDeclaration item() Method

Definition and Usage

item() The method returns the CSS property name by index (index).

The index starts from 0.

Instance

Example 1

Return the first CSS property name from the style declarations of the element "ex1":

var style = document.getElementById("ex1").style;
var propname = style.item(0);
alert(propname);

Experimente você mesmo

Example 2

Loop through all the style declarations of the elements:

for (i = 0; i < elmnt.style.length; i++) {
  txt += elmnt.style.item(i)
}

Experimente você mesmo

Sintaxe

style.item(index)

Parâmetros

Parâmetros Descrição
index Obrigatório. Número, que representa o índice (subscrito) da propriedade CSS.

Detalhes técnicos

Versão DOM: Modelo de Objeto CSS
Retorno: String que representa o nome da propriedade.

Suporte ao navegador

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Suporte 9.0 Suporte Suporte Suporte