Javascript DOM HTML CSSStyleDeclaration length Property

Introduction

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

Return the number of styles set on the H1 element:

Click the button to return the number of styles set on the H1 element:

View in separate window

<!DOCTYPE html>
<html>
<body>

<h1 style="color: red; font-size: 50px;">The length Property</h1>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//  w  w  w . j  av  a  2 s  .  co  m
  var elmnt = document.getElementsByTagName("h1")[0];
  var x = elmnt.style.length;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The length property returns a Integer representing the number of style declaration set for the element.




PreviousNext

Related