Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set max-height using javascript

Tags:

javascript

css

I have a div, and the maximum width for this div is user defined. I know I can get it done using element.style.height but this doesn't work in IE.

Any ideas on how to implement the max-height equivalent of Firefox by using javascript?

like image 411
Vinay Pandey Avatar asked Feb 11 '10 13:02

Vinay Pandey


People also ask

What is the use of max-height?

The max-height CSS property sets the maximum height of an element. It prevents the used value of the height property from becoming larger than the value specified for max-height .

What is Max-height 100vh?

A height of 100vh corresponds to the maximum possible viewport height. Since the initial viewport height is smaller, the body element with a min-height of 100vh initially exceeds the viewport height regardless of its content.

Is there a max-height in CSS?

The max-height property in CSS is used to set the maximum height of a specified element. Authors may use any of the length values as long as they are a positive value. max-height overrides height, but min-height always overrides max-height .


2 Answers

Usually style attribute names are translated into javascript property names by removing the hyphens and camelcase the name instead.

So background-color becomes backgroundColor, text-align becomes textAlign and max-height becomes maxHeight.

You can set an element el's maximum height to mHeight by:

el.style.maxHeight=mHeight;

Remember to use a valid value for mHeight.

like image 175
GodsBoss Avatar answered Oct 03 '22 17:10

GodsBoss


document.getElementById ( "yourelementid" ).style.maxHeight = "100px";

See maxHeight Property

maxHeight was introduced in Windows Internet Explorer 7

like image 24
rahul Avatar answered Oct 03 '22 18:10

rahul