Home > Web Front-end > Front-end Q&A > How to modify td width in jquery

How to modify td width in jquery

青灯夜游
Release: 2022-05-16 15:21:23
Original
2601 people have browsed it

3 methods: 1. Use the "$("td").width (width value)" statement to set the width of the td element. 2. Use the "$("td").css("width","width value")" statement to add a width style to the td element. 3. Use "$("td").css("width","width value")".

How to modify td width in jquery

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

There are many ways to modify the width of elements in jquery:

  • ##width()

  • css()

  • attr()

Let me introduce it to you.

1. Use the width()

width() method to set 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() {
					$("td").width(200); 
				});
			});
		</script>
	</head>

	<body class="ancestors">
		<table border="1">
			<tr>
				<th>商品</th>
				<th>价格</th>
			</tr>
			<tr>
				<td>T恤</td>
				<td>¥100</td>
			</tr>
			<tr>
				<td>牛仔褂</td>
				<td>¥250</td>
			</tr>
			<tr>
				<td>牛仔库</td>
				<td>¥150</td>
			</tr>
		</table><br>
		<button>修改td宽度</button>
	</body>

</html>
Copy after login

How to modify td width in jquery

2. Use css()

Use css() to add width style to td element

$(document).ready(function() {
	$("button").click(function() {
		$("td").css("width","100px"); 
	});
});
Copy after login

How to modify td width in jquery

3. Use attr()

Use attr() to control the style attribute value and add the width style to the td element

$(document).ready(function() {
	$("button").click(function() {
		$("td").attr("style","width:150px");
	});
});
Copy after login

How to modify td width in jquery

【Recommended learning:

jQuery video tutorial, web front-end video

The above is the detailed content of How to modify td 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