Javascript DOM CSS Style fontSize Property get

Introduction

Return the font size of a <p> element:

alert(document.getElementById("myP").style.fontSize);

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP" style="font-size:200%">This is a paragraph.</p>

<button type="button" onclick="myFunction()">Return font size</button>

<p id="demo"></p>
<script>
function myFunction() {/*from w ww  .  j a v  a 2  s .  com*/
  document.getElementById("demo").innerHTML = document.getElementById("myP").style.fontSize;
}
</script>

</body>
</html>



PreviousNext

Related