1

I am working on an MVC framework for javascript, where the content is rendering from XML. I am stucked in a problem.I need to find the font-size of textinput that is generating dynamically from xml. Based upon the font-size of text input I have to do some calculation.

Is there a way to calculate the font-size of text coming inside the textinput.

I can use Jquery/javascript for this purpose.

Thanks in advance

3 Answers 3

2

Javascript:

var size = document.getElementById("inputId").style.fontSize;

Note: You can only get font size if it is set using inline css

Better solution is Jquery

var size = $('#inputId').css("font-size");

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

That's only going to work if the font size is set using inline CSS in the first place
@Quentin you are correct so i have added jquery solution also
1

You can use jquery:

var fontsize = $('#yourtextinputid').css("font-size");// Returns a string such as "19px".

Please note that this will append "px" along with the size.

Comments

0

If you wan't a pure Javascipt solution try this:

var input = document.getElementById('some-input-field');
var fontSize = window.getComputedStyle(input, null).getPropertyValue("font-size");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.