Home  >  Article  >  Web Front-end  >  How to remove the content in td with jquery

How to remove the content in td with jquery

青灯夜游
青灯夜游Original
2021-11-16 13:47:442430browse

How to remove the content in td in jquery: 1. Use the "$("td")" statement to obtain the td object; 2. Use the html() method to set the content of the td object to empty and then remove it. The content of the td object, the syntax is "$("td").html("")".

How to remove the content in td with jquery

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

jquery removes the content in td

In jquery, you can use the html() method to remove the content in td.

html() method returns or sets the content (inner HTML) of the selected element.

Just use the html() method to set the content of the td element to empty.

Implementation code:

<!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() {
					$("td").html("");
				});
			});
		</script>
	</head>
	<body>
		<table border="1">
			<caption>人物信息</caption>
			<tr>
				<th>姓名</th>
				<th>年龄</th>
			</tr>
			<tr>
				<td>Peter</td>
				<td>20</td>
			</tr>
			<tr>
				<td>Lois</td>
				<td>20</td>
			</tr>
		</table><br />
		<button>点击按钮,去除td中的内容</button>
	</body>
</html>

How to remove the content in td with jquery

Related tutorial recommendations: jQuery video tutorial

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