Get the font of a <p> element: - Javascript CSS Style Property

Javascript examples for CSS Style Property:fontFamily

Description

Get the font of a <p> element:

Demo Code

ResultView the demo 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>

<script>
function myFunction() {/*from  www  .  jav  a  2s. c  om*/
    console.log(document.getElementById("myP").style.fontFamily);
}
</script>

</body>
</html>

Related Tutorials