Home>Article>Web Front-end> How to remove the attribute of a tag in jquery

How to remove the attribute of a tag in jquery

青灯夜游
青灯夜游 Original
2022-05-17 18:41:24 2199browse

Two methods: 1. Directly use removeAttr() to remove the specified attribute of the a tag, the syntax is "$("a").removeAttr("The name of the attribute to be removed")". 2. Use attr() to set the value of the attribute specified by the a tag to empty, using the syntax "$("a").attr("The name of the attribute to be removed","")".

How to remove the attribute of a tag in jquery

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

Two methods for jquery to remove attributes specified by a tag

1. Use removeAttr()

removeAttr() method removes the specified attribute from the selected element. Syntax:

$("a").removeAttr("要移除的属性名")

Example: Remove the target attribute of the a tag

      
a标签超链接

How to remove the attribute of a tag in jquery

2. Use attr()

attr() method sets or returns the attribute value of the selected element.

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

Syntax:

$("a").attr("要移除的属性名","")

Example: Remove the href attribute of the a tag

      
a标签超链接

How to remove the attribute of a tag in jquery

Extended knowledge:

tag defines a hyperlink that is used to link from one page to another. The most important attribute of the

element is the href attribute, which specifies the target of the link.

Attributes that can be set by tags

##rel rev ##Not supported in HTML 5. ##shape default mime_type Note: MIME = Multipurpose Internet Mail Extensions. [Recommended learning: jQuery video tutorial ,
Attributes Value Description
charset char_encoding Not supported in HTML 5.
coords coordinates Not supported in HTML 5.
href URL The target URL of the link.
hreflang language_code Specifies the base language of the target URL. Only used if the href attribute is present.
media media query

Specifies the media type of the target URL.

Default value: all. Only used if the href attribute is present.

name section_name Not supported in HTML 5.
    alternate
  • archives
  • author
  • bookmark
  • contact
  • external
  • first
  • help
  • icon
  • index
  • last
  • license
  • next
  • nofollow
  • noreferrer
  • pingback
  • prefetch
  • prev
  • search
  • stylesheet
  • sidebar
  • tag
  • up
Requires current The relationship between the document and the target URL.

Only used when href attribute exists.

text
    rect
  • circle
  • poly
Not supported in HTML 5.
##target
_blank _parent
  • _self
  • _top
  • Where to open the target URL. Only used if the href attribute is present.
type
Specifies the MIME type of the target URL. Only used if the href attribute is present.

web front-end video

]

The above is the detailed content of How to remove the attribute of a tag 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