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

How to remove html5 attributes in jq

青灯夜游
青灯夜游Original
2022-07-29 18:06:272100browse

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"

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" />

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)
Parameters Description
attribute Required. 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>

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!

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