6

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/

1

3 Answers 3

15

I have also faced the same problem.

I have tried the maxHeight property. Now the problem has been resolved

$('#exampleId').css({"maxHeight":"100px"});
Sign up to request clarification or add additional context in comments.

Comments

2

Changing max-height to height fixes your problem.

Demo

Comments

0

Not sure if earlier browsers had this issue. Tested recently in Chrome 56.x, FF 51.0.x and IE 11, you can use:

max-height: none;

so this works

alert('after set: ' + $('.holder').css('max-height','none'));//alert after set

One can use this as well with jquery (tested with 2.0.3) and create a toggle

$('#someid').toggleClass("expand");

and css

.expand{
   max-height: none !important;
}

1 Comment

how is it different than other answers

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.