Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 



Recommended Posts

Does anyone know how to check the font height assigned to a <div>, or anywhere? I need to know how tall the font is.

FontHeight=document.getElementById("ThisDIV").font-size;

Something like that. That doesn't work, of course.

Share this post


Link to post
Share on other sites

Hi,

In javascript a style property is write from CSS property name by removing the '-' and put an uppercase letter on the second word

x=document.getElementById("yourID").style.fontSize;

I have just test this :

The property must be set explicitly on the element by style="font-size:5px"

Example :

.test {font-size:9pt;} // class somewhere
...
<div id=""youID" class="test"...
...
x=document.getElementById("yourID").style.fontSize;

don't work and return an empty string

<div id=""youID" style="font-size:9pt;" ....

the same statement return 9pt

Regards

Share this post


Link to post
Share on other sites

I am using a style sheet so I was not having any luck. I can't hardcode the font size in for where I want to use it. Any other ideas?

Share this post


Link to post
Share on other sites

I'm not sure I got it right, but if you want to define a class in css and apply it to a element via js, you should use

document.getElementById('elem').className = 'cname';

And the css class should be

.cname { ... }

LE: just reread the whole thread, I guess I got it wrong ... you mean you already applied the css style and the js property isn't working correctly?

Edited by sadicq

Share this post


Link to post
Share on other sites

It's for WPI. .txt is defined in the .css files. Make a <div>, but the content defines with class="txt" later on. I want to see what size the text is of the "txt" class. Maybe thay makes more sense?

The problem is, I need to know BEFORE the text is laid out.

So, what is the font height of the css class "txt" in themes/wpi.css? I want to know as soon as WPI is started.

Share this post


Link to post
Share on other sites

Well, I don't think you can do that the easy way ... maybe trying to read the css with js/vb or making a hidden div and apply the class to it (then read the property) could solve the problem ...

Share this post


Link to post
Share on other sites

With a CSS style sheet fontSize or fontHeight are not embedded in each element

Navigator read the CSS style sheet then apply style for each element when it display it.

Javascript cannot retrieve any information not embedded in the html document.

In fact first test was not necessary

Only way is to read the CSS file and detect the font attribute of class with a RegExp.

Share this post


Link to post
Share on other sites

I thought it might come down to reading the css file.....ugh.....

Thanks, guys

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

×