Home > Web Front-end > JS Tutorial > body text

How to set height in jquery css

藏色散人
Release: 2023-01-06 11:15:39
Original
1867 people have browsed it

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()
Copy after login

Set the height

Set the height of all matching elements.

Syntax

$(selector).height(length)
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!