Home  >  Article  >  Web Front-end  >  How to modify the height of an element in jquery

How to modify the height of an element in jquery

青灯夜游
青灯夜游Original
2022-03-11 13:50:525548browse

Jquery method to modify element height (height): 1. Use the css() method, syntax "$(selector).css("height","height value")"; 2. Use height() Method, syntax "$(selector).height("height value")".

How to modify the height of an element in jquery

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

jquery modifies the height of the element

Method 1: Use the css() method

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(document).ready(function() {
				$("button").click(function() {
					$("img").css("height","200px");
				});
			});
		</script>
	</head>
	<body>

		<img  src="img/1.jpg"    style="max-width:90%"/ alt="How to modify the height of an element in jquery" ><br>
		<button>修改元素的高度</button>
	</body>
</html>

How to modify the height of an element in jquery

Method 2: Use the height() method

The height() method returns or sets the height of the matching element.

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(document).ready(function() {
				$("button").click(function() {
					$("img").height("200px");
				});
			});
		</script>
	</head>
	<body>

		<img  src="img/1.jpg"    style="max-width:90%"/ alt="How to modify the height of an element in jquery" ><br>
		<button>修改元素的高度</button>
	</body>
</html>

How to modify the height of an element in jquery

[Recommended learning: jQuery video tutorial, web front-end video

The above is the detailed content of How to modify the height of an element in jquery. 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