Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 660
Zack Peterson Avatar asked Apr 29 '09 20:04

Zack Peterson


People also ask

How do I remove a single style property in CSS?

Setting the value of a style property to an empty string — e.g. $('#mydiv'). css('color', '') — removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's . css() method, or through direct DOM manipulation of the style property.

Which jQuery method is used to show selected elements by adjusting height?

jQuery height() Method The height() method sets or returns the height of the selected elements.

How do I change my height to 100% in CSS?

height:100vh The . box class has only 100vh which is 100% of the viewport height. When you set the height to 100vh, the box element will stretch its height to the full height of the viewport regardless of its parent height.


1 Answers

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)

like image 176
user268828 Avatar answered Sep 22 '22 01:09

user268828