mritter Posted May 17, 2008 Posted May 17, 2008 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.
sadicq Posted May 17, 2008 Posted May 17, 2008 Check this out.PS: I'm not quite active here at this time, but I'll be back soon .
t4user Posted May 17, 2008 Posted May 17, 2008 Hi,In javascript a style property is write from CSS property name by removing the '-' and put an uppercase letter on the second wordx=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 9ptRegards
mritter Posted May 19, 2008 Author Posted May 19, 2008 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?
sadicq Posted May 19, 2008 Posted May 19, 2008 (edited) 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 usedocument.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 May 19, 2008 by sadicq
mritter Posted May 19, 2008 Author Posted May 19, 2008 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.
sadicq Posted May 19, 2008 Posted May 19, 2008 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 ...
t4user Posted May 19, 2008 Posted May 19, 2008 With a CSS style sheet fontSize or fontHeight are not embedded in each elementNavigator 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.
mritter Posted May 21, 2008 Author Posted May 21, 2008 I thought it might come down to reading the css file.....ugh.....Thanks, guys
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now