We help IT Professionals succeed at work.
Get Started

How to determined Fontsize through Javascript?

Last Modified: 2013-11-11

In Javascript you can set the fontsize by document.execCommand("FontSize",0,"size") . I am using the Wysihat(built on top of Prototype) html editor and that is how it is done. However, for JS the size goes from 1 to 7.

My question is how do you determine what is the font size of the specific text selection in pixels? So, something like 8px,10px,12px and so on.

One can always grab the stylesheet style, but how can I figure out with size corresponds to the 1 to 7 range on JS's document.execCommand("FontSize",0,"size") ?

I assume that also varies from the type of the font. Any function that I can go and select to determine that

I am trying to build a font drop down menu. So far I can make it work, but the value on the box does not correspond to the one I have selected sometimes showing something like 17 instead of the value 3. They I need to have it properly updated with the selected value.

Anyway to convert that to 8,9,10,12,14 like on the Outlook email editor?

Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE