Home  >  Article  >  Web Front-end  >  How to set height in jquery css

How to set height in jquery css

藏色散人
藏色散人Original
2021-05-27 10:50:261877browse

The method for setting the height of jquery css is the height method. This method can return or set the height of the matching element. The syntax for setting the height is such as "$(selector).height(length)". The parameter length specifies the height of the element. high.

How to set height in jquery css

The operating environment of this article: Windows7 system, jquery3.2.1&&css3 version, DELL G3 computer

jQuery CSS operation - height() Method

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, the height of the matching element in pixels is returned.

Syntax

$(selector).height()

Set the height

Set the height of all matching elements.

Syntax

$(selector).height(length)

Parameters

length

Optional. Specifies the height of the element.

If no length unit is specified, the default px unit is used.

Example:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".btn1").click(function(){
    $("p").height(50);
  });
});
</script>
</head>
<body>
<p style="background-color:yellow">This is a paragraph.</p>
<button class="btn1">改变高度</button>
</body>
</html>

Effect screenshot:

How to set height in jquery css

Recommended learning: "jquery video tutorial"

The above is the detailed content of How to set height in jquery css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn