Javatpoint Logo
Javatpoint Logo

jQuery height()

The jQuery height() method is used to return the current computed height for the first element or set the height of every matched element. In other words, you can say that the height() method is used for two purposes:

To return height: When this method is used to return height, it returns the height of first matched element.

To set height: When this method is used to set height, it sets height of all matched elements.

This method is a very common jQuery dimension.

The before() and insertBefore() both methods are used to perform same task. The main difference between them is in syntax, and the placement of the content and the target.

Syntax:

To return the height:

To set the height:

To set the height by using a function:

Parameters of jQuery height() method

Parameter Description
Value This is a mandatory parameter. It specifies the height in px, em, pt, etc. its defauly unit is px.
Function (index, currentHeight) This is an optional parameter. This is used to specify a function that returns the new height of the selected element.
  • Index:It provides the index position of the element in the set.
  • currentHeight: It provides the current height of the selected element.

Example of jQuery height() method

Let's take an example to demonstrate the jQuery height() method.

To return Height:

Test it Now

jQuery height() example 2

To set height:

This example will show how to set a specific height.

Test it Now




Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA