Javascript DOM CSS Style fontWeight Property get

Introduction

Return the font weight of a <p> element:

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP" style="font-weight:bold">This is a paragraph.</p>
<button type="button" onclick="myFunction()">Return font weight</button>
<p id="demo"></p>
<script>
function myFunction() {/*  w w w .j a  v  a  2  s .  co  m*/
  document.getElementById("demo").innerHTML = document.getElementById("myP").style.fontWeight;
}
</script>

</body>
</html>



PreviousNext

Related