3

I have an element with the style min-height: calc(50% + 10px). How can I get this calculation (i.e. "calc(50% + 10px)", not the current pixel value) with JavaScript? This does what I need in Chrome, but Firefox just gives me the result of the calculation:

getComputedStyle(myEle).minHeight

Fiddle: http://jsfiddle.net/P37FQ/1/

The reason why I need the exact "calc" string is that I have to temporarily remove the original min-height setting in a script, then restore it later.

1 Answer 1

3

An alternative solution is to instead of saving the CSS value, you can simply set the style to an empty string:

myEle.style.minHeight = '';

This will remove the style applied with JavaScript and therefore use the next value, which is the style from the stylesheet.

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

1 Comment

See, this is why I always include the reason for asking a question. This completely solves my problem, making the actual question redundant :)

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.