How to modify element width (width) in jquery

青灯夜游
Release: 2022-05-16 18:25:37
Original
5814 people have browsed it

Methods to modify element width (width): 1. Use width() to directly set the width value, the syntax is "$(selector).width("width value")"; 2. Use css() to add width New style, the syntax is "$(selector).css("width","width value")".

How to modify element width (width) in jquery

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

jquery changes element width (width)

##1. Use the width() method

The width() method returns or sets the width 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").width("200px");
				});
			});
		</script>
	</head>
	<body>

		<img  src="1.jpg"    style="max-width:90%"/ alt="How to modify element width (width) in jquery" ><br>
		<button>修改元素的宽度</button>
	</body>
</html>
Copy after login

How to modify element width (width) in jquery

2. 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("width","250px");
				});
			});
		</script>
	</head>
	<body>

		<img  src="1.jpg"    style="max-width:90%"/ alt="How to modify element width (width) in jquery" ><br>
		<button>修改元素的宽度</button>
	</body>
</html>
Copy after login

How to modify element width (width) in jquery

[Recommended learning:

jQuery video tutorialweb front-end video

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