Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSSStyleDeclaration length attribute

CSSStyleDeclaration length attribute

CSS CSSStyleDeclaration CSS CSSStyleDeclaration

Example

Return the number of style declarations for the h1 element:

var

elmnt

=

document

.

getElementsByTagName

(

"

h1

"

)

[

0

]

;

var

x

=

style

.

length

;

Try it »


Definition and usage

The length attribute returns the number of style declarations for the specified element.


Browser support

property
length Yes Yes Yes Yes Yes

Syntax

Return the length attribute:

element.style.length


Technical Details

DOM version: CSS Object Model
Return value: An integer representing the number of CSS declarations

More examples

Example

Loop through and output all inline CSS property names of the specified element:

for

(

i

=

0

;

i

<

elmnt

.

style

.

length

;

i

++

)

{

txt

+=

elmnt

.

style

.

item

(

i

)

}

Try it »

CSS CSSStyleDeclaration CSS CSSStyleDeclaration