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.
To return the height:
To set the height:
To set the height by using a function:
Parameters of jQuery height() method
|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.
Example of jQuery height() method
Let’s take an example to demonstrate the jQuery height() method.
To return Height:
jQuery height() example 2
To set height:
This example will show how to set a specific height.