CSSStyleDeclaration length attribute
Definition and Usage
length
The property returns the number of style declarations set for the specified element.
Instance
Example 1
Return the number of styles set on the h1 element:
var elmnt = document.getElementsByTagName("h1")[0]; var x = style.length;
Example 2
Loop through all the style declarations of the elements:
for (i = 0; i < elmnt.style.length; i++) { txt += elmnt.style.item(i) }
Syntax
Returns the length property:
element.style.length
Technical Details
DOM Version: | CSS Object Model |
---|---|
Return Value: | Integer, representing the number of style declarations set for the element. |
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |