How do I remove the height style from a DIV using jQuery?

106,663

Solution 1

to remove the height:

$('div#someDiv').css('height', '');
$('div#someDiv').css('height', null);

like John pointed out, set height to auto:

$('div#someDiv').css('height', 'auto');

(checked with jQuery 1.4)

Solution 2

$('div#someDiv').height('auto');

I like using this, because it's symmetric with how you explicitly used .height(val) to set it in the first place, and works across browsers.

Solution 3

you can try this:

$('div#someDiv').height('');

Solution 4

maybe something like

$('div#someDiv').css("height", "auto");

Solution 5

To reset the height of the div, just try

$("#someDiv").height('auto');

Share:
106,663
Zack Peterson
Author by

Zack Peterson

Specializes in the design and creation of web and desktop applications. Contributes in all aspects of the software development process such as: requirements analysis and product definition; prototyping; choosing architecture and framework; interface design; database design; installation and integration; documentation and training; gathering feedback; and maintenance.

Updated on September 11, 2020

Comments

  • Zack Peterson
    Zack Peterson almost 4 years

    By default, a DIV's height is determined by its contents.

    But, I override that and explicitly set a height with jQuery:

    $('div#someDiv').height(someNumberOfPixels);
    

    How can I reverse that? I want to remove the height style and to make it go back to it's automatic/natural height?