I am using angular, but I assume I can use any DOM manipulation for this ?
Asked
Active
Viewed 4,217 times
2 Answers
7
You can use getComputedStyle()
and getPropertyValue()
.
Here's a running example:
var test = document.getElementById("test");
var result = document.getElementById("result");
result.value = getComputedStyle(test).getPropertyValue("font-family");
#test {
font-family: "Trebuchet MS",sans-serif;
}
<span id="test">What font family am I?</span>
<input id="result"></input>

Dave
- 10,748
- 3
- 43
- 54
-
2023 checkup: is there a way to get the name of the font actually being loaded and rendered? – aetonsi Aug 08 '23 at 09:06
2
If you have jQuery you can use this:
$('#some-selector').css('font-family');
You can use vanilla JS too, but it is a bit more involved. Here is an example using getComputedStyle
:
getComputedStyle in pure Javascript?