Home > Web Front-end > Front-end Q&A > How to remove html5 attributes in jq

How to remove html5 attributes in jq

青灯夜游
Release: 2022-07-29 18:06:27
Original
2066 people have browsed it

Jquery steps to remove html5 attributes: 1. Use the jquery selector to select the specified html5 element. The syntax "$(selector)" will return a jquery object containing the specified element; 2. Use the removeAttr() function Remove the specified attribute of the element object, the syntax is "element object.removeAttr("attribute name")".

How to remove html5 attributes in jq

The operating environment of this tutorial: windows7 system, jquery3.6.0 version, Dell G3 computer.

html5 attributes

Attributes can provide some additional information for HTML tags, or modify HTML tags. Attributes need to be added in the start tag, and the syntax format is:

attr="value"
Copy after login

attr represents the attribute name, and value represents the attribute value. Attribute values ​​must be surrounded by double quotes " " or single quotes ' '.

<input type="text" id="username" />
Copy after login

type and id are attributes.

#How does jq remove html5 attributes?

In jquery, you can use removeAttr() to delete attributes.

removeAttr() method can remove the specified attribute from the selected html element.

Syntax:

$(selector).removeAttr(attribute)
Copy after login
ParametersDescription
attributeRequired. Specifies the attributes to remove from the specified element.

Example: Use removeAttr() to delete the hidden attribute

The hidden attribute specifies that the element is hidden. Hidden elements will not be displayed.

Delete this attribute to allow the element to be displayed.

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<script src="js/jquery-3.6.0.min.js"></script>
		<script>
			$(function() {
				$("button").click(function() {
					$("p").removeAttr("hidden");
				})
			})
		</script>
	</head>
	<body>
		<p>这是一段可见的段落。</p>
		<p hidden="hidden">这是一段被隐藏的段落,现在显示出来了。</p>
		<p>这是一段可见的段落。</p>
		<button>删除hidden属性</button>
	</body>
</html>
Copy after login

How to remove html5 attributes in jq

Recommended related tutorials: jQuery video tutorial

The above is the detailed content of How to remove html5 attributes in jq. 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