Javascript examples for jQuery Method and Property:height
The height() method sets or gets the height of the selected elements.
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 |
The following code shows how to Return the height of a <div> element:
<!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>