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

What is the usage of jquery attr

藏色散人
Release: 2021-11-11 09:06:04
Original
4194 people have browsed it

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)
Copy after login

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)
Copy after login

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))
Copy after login

Parameters

attribute specifies the name of the attribute.

function(index,oldvalue)
Copy after login

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 ...})
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template