Home >>jQuery Tutorial >jQuery height() Method

jQuery height() Method

jQuery height() Method

jQuery height() method in jQuery is used to sets or returns the height of the selected given elements and it returns the height of the FIRST matched element.

Return the height: $(selector).height()
Set the height: $(selector).height(value)
Set the height using a function: $(selector).height(function(index,currentheight))

Parameter Values

Parameter Description
Value It is a required parameter for setting height. Its Default unit is px and specifies the height in em, px, pt, etc.
function(index,currentheight) It is Optional parameter and is used to specifies a function that returns the new height of selected given elements
  • index – used to Returns the index position of the element
  • currentheight – used to Returns the current height of the selected element
Here is an Example of jQuery height() Method:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
alert("Height of div: " + $(".height1").height());
<div class="height1"  style="height:50px;width:150px;padding:10px;margin:3px;border:1px solid #000;background-color:#a4e838;"></div><br>
<button class="btn1">click me to display height</button>