Home  >  Article  >  Web Front-end  >  What is the usage of jquery attr

What is the usage of jquery attr

藏色散人
藏色散人Original
2021-11-11 09:05:504019browse

The function of jquery attr is to set or return the attribute value of the selected element. Its usage syntax is "$(selector).attr(attribute)", where the parameter attribute specifies the attribute whose value is to be obtained.

What is the usage of jquery attr

The operating environment of this article: windows7 system, jquery3.2.1 version, DELL G3 computer

#What is the usage of jquery attr?

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

According to the different parameters of this method, its working method is also different.

Return attribute value

Return the attribute value of the selected element.

Syntax

$(selector).attr(attribute)

Parameters

attribute specifies the attribute whose value is to be obtained.

Set attributes/values

Set the attributes and values ​​of the selected element.

Syntax

$(selector).attr(attribute,value)

Parameters

attribute specifies the name of the attribute.

value Specifies the value of the attribute.

Use functions to set attributes/values

Set the attributes and values ​​of the selected element.

Syntax

$(selector).attr(attribute,function(index,oldvalue))

Parameters

attribute specifies the name of the attribute.

function(index,oldvalue)

Specifies the function that returns the attribute value.

This function can receive and use the index value of the selector and the current attribute value.

Set multiple attribute/value pairs

Set more than one attribute and value for the selected element.

Syntax

$(selector).attr({attribute:value, attribute:value ...})

Parameters

attribute:value specifies one or more attribute/value pairs.

Recommended learning: "jquery video tutorial"

The above is the detailed content of What is the usage of jquery attr. 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