Home > Web Front-end > JS Tutorial > What is the function in jquery that can change the height of elements?

What is the function in jquery that can change the height of elements?

青灯夜游
Release: 2021-11-16 16:29:30
Original
2387 people have browsed it

Functions in jquery that can change the height of elements: 1. height(), which can set the height of matching elements, the syntax is "$(selector).height (height value)"; 2. css(), syntax "$(selector).css("height","height value")".

What is the function in jquery that can change the height of elements?

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

Function in jquery that can change the height of elements

##1. Height() function## The #height() method sets the height of the matching element.

Syntax:

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

    length Optional. Specifies the height of the element. If no length unit is specified, the default px unit is used.
  • Example:
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<script src="js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$("button").click(function() {
					$("div").height(100);
				});
			});
		</script>
		<style type="text/css">
			div {
				height: 50px;
				border: 1px solid red;
			}
		</style>
	</head>

	<body>
		<div></div>
		<br /><br />

		<button>改变div元素的高度</button>
	</body>
</html>
Copy after login

What is the function in jquery that can change the height of elements?

2. css() function

css( ) method sets the style attributes of the matching element.

Grammar:

$(selector).css(name,value)
Copy after login

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<script src="js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$("button").click(function() {
					$("div").css("height","200px");
				});
			});
		</script>
		<style type="text/css">
			div {
				height: 50px;
				border: 1px solid red;
			}
		</style>
	</head>

	<body>
		<div></div>
		<br /><br />

		<button>改变div元素的高度</button>
	</body>
</html>
Copy after login

What is the function in jquery that can change the height of elements? Recommended related tutorials:

jQuery video tutorial

The above is the detailed content of What is the function in jquery that can change the height of elements?. 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
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template