Home  >  Article  >  Web Front-end  >  How to remove specified attributes from td elements in jquery

How to remove specified attributes from td elements in jquery

青灯夜游
青灯夜游Original
2021-11-25 11:03:151562browse

In jquery, you can use the removeAttr() method to remove the specified attribute in the td element. The function of this method is to remove the specified attribute from all matching elements. The specific syntax is "$(" td").removeAttr("Attribute to be removed")".

How to remove specified attributes from td elements in jquery

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

In jquery, you can use the removeAttr() method to remove the specified attribute in the td element.

removeAttr() method can remove the specified attribute from all matching elements.

Syntax:

$(selector).removeAttr(attribute)
  • attribute: Specifies the attribute to be removed from the specified element and cannot be omitted.

Example: Remove the id attribute in the td element

<!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").removeAttr("id")
				});
			});
		</script>
		<style>
			#Peter{
				background-color: #FFC0CB;
			}
		</style>
	</head>
	<body>
		<table border="1">
			<caption>人物信息</caption>
			<tr>
				<th>姓名</th>
				<th>年龄</th>
			</tr>
			<tr>
				<td id="Peter">Peter</td>
				<td>20</td>
			</tr>
			<tr>
				<td>Lois</td>
				<td>20</td>
			</tr>
		</table><br />
		<button>移除td中的id属性</button>
	</body>
</html>

How to remove specified attributes from td elements in jquery

Related tutorial recommendations:jQuery video tutorial

The above is the detailed content of How to remove specified attributes from td elements 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