jQuery CSS Operation - height() Method
Example
Set the height of the <p> element:
$(".btn1").click(function(){ $("p").height(50); });
Definition and Usage
The height() method returns or sets the height of the matching element.
Return height
Return the height of the first matching element.
If no parameters are set for this method, it returns the height of the matching element in pixels.
Syntax
$(selector).height()
Set height
Set the height of all matching elements.
Syntax
$(selector).height(length)
Parameters | Description |
---|---|
length |
Optional. Specify the height of the element. If no length unit is specified, the default px unit is used. |
Use a function to set height
Use a function to set the height of all matching elements.
Syntax
$(selector).height(function(index,oldheight))
Parameters | Description |
---|---|
function(index,oldheight) |
Specify a function that returns the new height of the selected element.
|
More examples
- Get the height of the document and window elements
- Use the height() method to get the current height of the document and window elements.
- Use em and % values to set the height
- Set the height of the element using the specified length unit.