jQuery CSS Operation - height() Method

Example

Set the height of the <p> element:

$(".btn1").click(function(){
  $("p").height(50);
});

Try it yourself

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()

Try it yourself

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.

Try it yourself

Use a function to set the height

Use a function to set the height of all matching elements.

Syntax

$(selector).height(function(index,oldheight))
Parameters Description
function(index,oldheight)

Specify the function that returns the new height of the selected element.

  • index - Optional. Accepts the index position of the selector
  • oldvalue - Optional. Accepts the current value of the selector.

Try it yourself

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
Use the specified length unit to set the height of the element.