Javascript DOM CSS Style fontFamily Property get

Introduction

Return the font of a <p> element:

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP" style="font-family:Arial,Helvetica,sans-serif;">
This is a paragraph, shown in the Arial font.</p>

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

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


<script>
function myFunction() {/*  w w w .j a  va 2  s  .co  m*/
  document.getElementById("demo").innerHTML = document.getElementById("myP").style.fontFamily;
}
</script>
</body>
</html>



PreviousNext

Related