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")".
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>
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!