Home >>jQuery Tutorial >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.
Syntax:Return the height: | $(selector).height() |
Set the height: | $(selector).height(value) |
Set the height using a function: | $(selector).height(function(index,currentheight)) |
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
|
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
alert("Height of div: " + $(".height1").height());
});
});
</script>
</head>
<body>
<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>
</body>
</html>