Home>Article>Web Front-end> How to delete an attribute of a div in jquery

How to delete an attribute of a div in jquery

青灯夜游
青灯夜游 Original
2022-05-23 18:04:53 3215browse

Two deletion methods: 1. Use attr() to delete, the syntax is "$("div").attr("attribute name","");", you can set the value of the specified attribute to Empty, thereby invalidating the attribute; 2. Use removeAttr() to delete, the syntax is "$("div").removeAttr("Attribute name");".

How to delete an attribute of a div in jquery

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

What are 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 ' '.

Note that although both double quotes and single quotes can surround attribute values, for the sake of standardization and professionalism, please use double quotes as much as possible.

A tag can have no attributes or one or more attributes.

Two methods for jquery to delete an attribute of a div

Method 1: Use attr() to set the value of the specified attribute Is empty

When using the attr() method to set the attribute value of the selected element to empty, the specified attribute can also be invalidated.

     

这是一个标题

这是一个div元素。

这是一个p元素。

How to delete an attribute of a div in jquery

Method 2: Use removeAttr() to directly delete the specified attribute

removeAttr() method removes from the selected element One or more attributes. To remove several properties, separate the property names with spaces.

      

这是一个标题

这是一个div元素。
这是另一个div元素。

How to delete an attribute of a div in jquery

[Recommended learning:jQuery video tutorial,web front-end video

The above is the detailed content of How to delete an attribute of a div 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