3

I would like to be able to find out the font-family actually used for an element so that I can display it to the user in the document. Perhaps there something in the DOM which I can read with JavaScript to tell me this?

I realize I can find out from the DOM which font-family is specified in the document but I want to know which one is actually used by the browser.

C. Lamb
  • 31
  • 3
  • 2
    Visit the link: http://stackoverflow.com/questions/7444451/how-to-get-the-actual-rendered-font-when-its-not-defined-in-css – Mamun Apr 27 '17 at 05:09
  • I don't think it is possible, but you can make a javascript function that will execute a callback when a font file has been completely downloaded and loaded. – Bernard Apr 27 '17 at 05:10
  • On my system, thıs single text nِِԾde uses 3 different fonts . – Kaiido Apr 27 '17 at 05:15
  • Possible duplicate of [How to get the actual rendered font when it's not defined in CSS?](http://stackoverflow.com/questions/7444451/how-to-get-the-actual-rendered-font-when-its-not-defined-in-css) – Kaiido Apr 27 '17 at 05:18
  • Not quite a duplicate of 7444451 but a generalization of it. That question didn't seem to find a solution either. I tried getComputedFont but that just returned the value from the DOM. I suspect Bernard is right; there is no correct answer. – C. Lamb Apr 27 '17 at 21:16

1 Answers1

-1

You can do something like this:Assuming label is your DOM element, you can change the DOM element to anything you want. Is this you are looking for?

var elem = document.getElementById('one');
console.log(elem.style.fontFamily);
<label for="male" id="one" style="font-family:'Comic Sans MS', cursive">Male</label>
Pankaj Shukla
  • 2,657
  • 2
  • 11
  • 18