Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the font style (font-family) from an element

I am using angular, but I assume I can use any DOM manipulation for this ?

like image 799
Pacman Avatar asked Jan 17 '26 06:01

Pacman


1 Answers

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>
like image 126
Dave Avatar answered Jan 19 '26 19:01

Dave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!