I've tested this code for set .css('max-height','auto')
css property in JQuery but it's not working, and when I set a dimension like .css('max-height','93px')
it's working fine, how can I set it as auto
?
HTML:
<div class="holder">
<div>DIVISION</div>
<div>DIVISION</div>
<div>DIVISION</div>
<div>DIVISION</div>
<div>DIVISION</div>
<div>DIVISION</div>
<div>DIVISION</div>
</div>
<br />
<input type="button" onclick="test();" value="CHECK" />
CSS:
.holder{
max-height:40px;
background:red;
padding:10px;
overflow:hidden;
}
.holder div{
background:blue;
margin:3px 0;
}
js:
function test(){
var hldr=$('.holder'); //get element
alert('before set: ' + $('.holder').css('max-height')); //alert before set
/* SET */
hldr.css('max-height','auto');
alert('after set: ' + $('.holder').css('max-height'));//alert after set
}
http://jsfiddle.net/silverlight/23UCV/2/
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 .
maxHeight = 'none'; it will apply the none value to the max-height property of the element, overriding any other valid max-height properties in CSS selection rules that match that element.
Answer: Use the JavaScript height() method You can set the height of a <div> box dynamically using the jQuery height() method.
The max-height property defines the maximum height of an element. If the content is larger than the maximum height, it will overflow. How the container will handle the overflowing content is defined by the overflow property. If the content is smaller than the maximum height, the max-height property has no effect.
Changing max-height
to height
fixes your problem.
Demo
I have also faced the same problem.
I have tried the maxHeight property. Now the problem has been resolved
$('#exampleId').css({"maxHeight":"100px"});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With