Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery height() method

jQuery height() method

jQuery HTML/CSS methods jQuery HTML/CSS methods

Example

Return

The element's height:

$

(

"

button

"

)

.

click

(

function

(

)

{

alert

(

$

(

"

div

"

)

.

height

(

)

)

;

}

)

;

Try it »


Definition and Usage

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

When this method is used toReturnheight, it returns the height of the first matched element.

When this method is used toSettingsheight, it sets the height of all matched elements.

As shown in the image below, this method does not include padding, border, or margin.

jQuery Dimensions


Related methods:

  • width() - Sets or returns the width of an element
  • innerWidth() - Returns the width of an element (including padding)
  • innerHeight() - Returns the height of an element (including padding)
  • outerWidth() - Returns the width of an element (including padding and border)
  • outerHeight() - Returns the height of an element (including padding and border)

Syntax

Return the height:

$(

selector

).height()

Set the height:

$(

selector

).height(

value

)

Set the height using a function:

$(

selector

).height(function

(index,currentheight)

)

Parameters Description
value Required when setting the height. Specifies the height of the element, in px, em, pt, etc.
The default unit is px.
function*(index,currentheight)* Optional. Specifies a function that returns the new height of the selected elements.
  • index - Returns the index position of the element in the set.
  • currentheight - Returns the current height of the selected elements.
  • |

    More examples

    Set the height of an element
    How to set an element's height using different units.

    Increase the height using a function
    How to use a function to increase an element's height.

    Return the height of the document and window elements
    How to return the current height of the document and window elements.

    Display dimensions with related methods
    How to use width(), height(), innerHeight(), innerWidth(), outerWidth(), and outerHeight().


    jQuery HTML/CSS methods jQuery HTML/CSS methods