height() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:height

Description

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

Parameter

Parameter Require Description
value Required for setting height.Specifies the height in px, em, pt, etc. Default unit is px
function(index,currentheight) Optional. a function that returns the new height of selected elements
  • index - Returns the index position of the element in the set
  • currentheight - Returns the current height of the selected element

The following code shows how to Return the height of a <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        console.log("Height of div: " + $("div").height());
    });//w  ww .  j  a  va2s .com
});
</script>
</head>
<body>

<div style="height:100px;width:300px;padding:10px;margin:3px;border:1px solid blue;background-color:red;"></div><br>

<button>Display the height of div</button>

</body>
</html>

Related Tutorials